home *** CD-ROM | disk | FTP | other *** search
/ PC Open 107 / PC Open 107 CD 1.bin / CD1 / INTERNET / COPIA SITI / HTTrack / httrack.exe / {app} / src_win / WinHTTrack / Shell.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-01-03  |  106.2 KB  |  3,009 lines

  1. // Shell.cpp : Defines the class behaviors for the application.
  2. //
  3.  
  4. // thread windows
  5. #include <process.h>
  6.  
  7. #include "stdafx.h"
  8. #include "Shell.h"
  9. #include "NewProj.h"
  10.  
  11. #include "htsbase.h"
  12.  
  13. // Ras
  14. #if USE_RAS 
  15. #include "RasLoad.h"
  16. #endif
  17.  
  18. #include <afxdisp.h>
  19. #include "ras.h"
  20. #include "mmsystem.h"
  21.  
  22. //#include "ShellDoc.h"
  23. //#include "ShellView.h"
  24.  
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30.  
  31. // PATCH-->
  32. // PATCH-->
  33. #include "about.h"
  34. #include "infoend.h"
  35.  
  36. // flag de termination
  37. int termine=0;
  38. int termine_requested=0;
  39. int shell_terminated=0;
  40. int soft_term_requested=0;
  41. FILE* fp_debug=NULL;
  42.  
  43. #include "stdafx.h"
  44. #include "Shell.h"
  45. #include "process.h"
  46. //#include "ShellDoc.h"
  47. //#include "ShellView.h"
  48. //#include "essai.h"
  49. //#include "get.h"
  50. //#include "parameter.h"
  51. extern "C" {
  52.   #include "HTTrackInterface.h"
  53.   #include "htssystem.h"
  54. }
  55. #include "Wid1.h"
  56. #include "trans.h"
  57. #include "InfoUrl.h"
  58. //#include "option.h"
  59. //#include "filter.h"
  60. //#include "wizard.h"
  61. //
  62. #include "maintab.h"
  63. //
  64. #include "MemRegister.h"
  65.  
  66. // LANG
  67. #include "newlang.h"
  68.  
  69.  
  70. // PATCH-->
  71. //#include "wizard2.h"
  72. //#include "WizLinks.h"
  73.  
  74. #include "inprogress.h"
  75.  
  76. #include "SYS\TIMEB.H"
  77.  
  78. // htswrap_add
  79. extern "C" {
  80.   #include "htswrap.h"
  81. };
  82.  
  83. // --- --- --- --- Options --- --- --- ---
  84.  
  85. #define MAX_LEN_INPROGRESS 32
  86.  
  87. // lancement en multithread du shell ET de gethostbyname
  88. #define SHELL_MULTITHREAD 1
  89. //#define HTS_XGMETHOD 2    // 1: AfxBeginThread 2: _beginthread
  90. // --- --- --- --- Options --- --- --- ---
  91. //int INREDRAW_LOCKED=0;      // refresh graphique en cours
  92. //int INFILLMEM_LOCKED=0;     // refresh mΘmoire en cours
  93. int HTTRACK_result=0;
  94. //
  95. CInfoUrl* _Cinprogress_inst=NULL;
  96.  
  97. extern HICON httrack_icon;
  98.  
  99. /* Main splitter frame */
  100. #include "DialogContainer.h"
  101. #include "splitter.h"
  102. extern CSplitterFrame* this_CSplitterFrame;
  103.  
  104. /* Main WizTab frame */
  105. #include "WizTab.h"
  106. extern CWizTab* this_CWizTab;
  107. /* Argh - pas de domodal dans des autres threads ?!?! */
  108. char WIZ_question[1000];
  109. char WIZ_reponse[1000];
  110.  
  111.  
  112. // Fonctionnement des THREADS:
  113. //
  114. // principal ---> robot & refresh data (thread 1)
  115. //           ---> refresh graphique    (thread 2)
  116. //           GO!> boucle gestion domodal() et boutons
  117. // arrΩt: principal demande l'arrΩt (termine_requested)
  118. //        thread1 active termine et que thread2 ait fini de refresher
  119. //        thread2 se termine
  120. //        thread1 retourne 0 α hts_loop
  121. //        le robot termine
  122. //        le thread1 active termine, termine le formulaire et se termine
  123. //        principal ayant quittΘ le formulaire affiche le message de fin
  124.  
  125.  
  126. // htslib.c
  127. extern "C" {
  128.   HTSEXT_API void qsec2str(char *st,TStamp t);
  129. }
  130.  
  131. // construction index gΘnΘral
  132. // void Build_TopIndex();
  133.  
  134. void compute_options() ;
  135. static void StripControls(char * chaine);
  136. void lance(void);
  137. int check_continue(char* pathlog);
  138. int inprogress_refresh();
  139. //int inprogress_refresh_scan();
  140. void Write_profile(CString path,int load_path);
  141. void Read_profile(CString path,int load_path);
  142.  
  143.  
  144. // dΘja fait mais bon
  145. #define HTS_WIN 1
  146.  
  147. extern "C" {
  148.   #include "htscore.h"
  149. }
  150.  
  151. CString _HTTRACK_VERSION = HTTRACK_VERSION;
  152.  
  153. CShellOptions* ShellOptions;
  154.  
  155.  
  156. // Fichier tempo
  157. FILE* tmpf=NULL;
  158. MemRegister tmpm;
  159.  
  160. CNewProj* dialog0=NULL;
  161. Wid1* dialog1=NULL;
  162. Ctrans* dialog2=NULL;
  163. //Coption dialog3;
  164. //Cfilter diafiltre;
  165. /*
  166. wizard diawiz;
  167. wizard2 diawiz2;
  168. WizLinks diawiz3;
  169. */
  170. //
  171. CMainTab* maintab=NULL;
  172. CShellApp* CShellApp_app=NULL;
  173.  
  174. #include "infoend.h"
  175. extern Cinfoend* this_Cinfoend;
  176.  
  177.  
  178. // PATCH-->
  179. Cinprogress* inprogress=NULL;
  180.  
  181. // nbre de slides
  182. t_StatsBuffer StatsBuffer[NStatsBuffer];
  183. void* StatsBufferback=NULL;
  184. int StatsBufferback_max=0;
  185. InpInfo SInfo;
  186.  
  187. #if USE_RAS
  188. // Chargement des librairies RAS
  189. CDynamicRAS* LibRas=NULL;
  190. int LibRasUse=0;
  191. //
  192. int connected=0;
  193. int disconnect=0;
  194. int shutdown_pc=0;
  195. HRASCONN conn = NULL;
  196. int has_started=0;
  197. char connected_err[1000]="";
  198. #endif
  199.  
  200. // pour message final
  201. extern char end_mirror_msg[8192];
  202. #include "winhttrack.h"
  203. extern CWinHTTrackApp* this_app;
  204.  
  205.  
  206. // PATCH-->
  207. // PATCH-->
  208. // FIN PATCH
  209.  
  210.  
  211. /////////////////////////////////////////////////////////////////////////////
  212. // CShellApp
  213.  
  214. /*
  215. BEGIN_MESSAGE_MAP(CShellApp, CWinApp)
  216. //{{AFX_MSG_MAP(CShellApp)
  217. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  218. // NOTE - the ClassWizard will add and remove mapping macros here.
  219. //    DO NOT EDIT what you see in these blocks of generated code!
  220. //}}AFX_MSG_MAP
  221. // Standard file based document commands
  222. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  223. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  224. // Standard print setup command
  225. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  226. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  227. END_MESSAGE_MAP()
  228. */
  229.  
  230. /////////////////////////////////////////////////////////////////////////////
  231. // CShellApp construction
  232.  
  233. CShellApp::CShellApp()
  234. {
  235.   // TODO: add construction code here,
  236.   // Place all significant initialization in InitInstance
  237. }
  238.  
  239. /////////////////////////////////////////////////////////////////////////////
  240. // The one and only CShellApp object
  241.  
  242. //CShellApp theApp;
  243.  
  244. /////////////////////////////////////////////////////////////////////////////
  245. // CShellApp initialization
  246.  
  247. static void __cdecl RunBackMirror( LPVOID pP ) {
  248.   CShellApp_app->init_lance();
  249. }
  250.  
  251. BOOL LaunchMirror() {
  252.   WHTT_LOCK();
  253.   hts_resetvar();
  254.   WHTT_UNLOCK();
  255.   (void)hts_newthread(RunBackMirror, 0, NULL);
  256.   return 0;
  257. }
  258.  
  259. #if 0
  260. BOOL CShellApp::InitInstance()
  261. {
  262.   CShellApp_app=this;
  263.   termine=termine_requested=shell_terminated=soft_term_requested=0;
  264.   
  265.   // Initialize OLE libraries
  266.   /*
  267.   if (!AfxOleInit())
  268.   {
  269.   AfxMessageBox(LANG(LANG_F1));
  270.   return FALSE;
  271.   }
  272.   AfxEnableControlContainer();
  273.   */
  274.   
  275.   // Fixer localisation dans la base de registre
  276.   //SetRegistryKey("WinHTTrack");
  277.   
  278.   // Standard initialization
  279.   // If you are not using these features and wish to reduce the size
  280.   //  of your final executable, you should remove from the following
  281.   //  the specific initialization routines you do not need.
  282.   /*
  283.   #ifdef _AFXDLL
  284.   Enable3dControls();            // Call this when using MFC in a shared DLL
  285.   #else
  286.   Enable3dControlsStatic();    // Call this when linking to MFC statically
  287.   #endif
  288.   */
  289.   
  290.   // Register the application's document templates.  Document templates
  291.   //  serve as the connection between documents, frame windows and views.
  292.   
  293.   // Change the registry key under which our settings are stored.
  294.   // You should modify this string to be something appropriate
  295.   // such as the name of your company or organization.
  296.   //SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  297.   
  298.   //LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  299.   
  300.   // Register the application's document templates.  Document templates
  301.   //  serve as the connection between documents, frame windows and views.
  302.   
  303.   // Parse command line for standard shell commands, DDE, file open
  304.   /*CCommandLineInfo cmdInfo;
  305.   ParseCommandLine(cmdInfo);
  306.   */
  307.   
  308.   _Cinprogress_inst=NULL;
  309.   
  310.   LibRasUse=0;
  311.   
  312.   /*
  313.   #if USE_RAS
  314.   LibRas=new CDynamicRAS();
  315.   if (LibRas->IsRASLoaded()) 
  316.   LibRasUse=1;
  317.   else
  318.   LibRasUse=0;
  319.   #endif
  320.   */
  321.   
  322.   maintab = new CMainTab("WinHTTrack Website Copier");
  323.   
  324.   // PATCH-->
  325.   // ΘxΘcution..
  326.   init_lance();
  327.   
  328.   delete maintab;
  329.   maintab=NULL;
  330.   
  331.   // PATCH-->
  332.   /*
  333.   // Dispatch commands specified on the command line
  334.   if (!ProcessShellCommand(cmdInfo))
  335.         return FALSE;
  336.     
  337.       // The one and only window has been initialized, so show and update it.
  338.       m_pMainWnd->ShowWindow(SW_SHOW);
  339.       m_pMainWnd->UpdateWindow();
  340.   */  
  341.   
  342.   
  343.   return TRUE;
  344. }
  345. #endif
  346.  
  347. // PATCH-->
  348. // routines diverses
  349.  
  350. char* _SN(LLint n) {
  351.   static char str[256];
  352.   str[0]='\0';
  353.   sprintf(str,LLintP,(LLint)n);        /* 64-bit */
  354.   return str;
  355. }
  356.  
  357. // t existe-t-il comme rΘpertoire?
  358. int dir_check(char* t) {
  359.   int dir;
  360.   FILE* fp=fopen(t,"rb");
  361.   dir=(errno==13);  // is directory
  362.   if (fp) fclose(fp);
  363.   return dir;
  364. }
  365.  
  366. void check_temp(char* t,char* s) {
  367.   if (strlen(s)==0)
  368.     if (dir_check(t))
  369.       strcpybuff(s,t);
  370. }
  371.  
  372.  
  373.  
  374. // PATCH-->
  375. // Routines gestion dials
  376. // PatchΘ pour 100% dials
  377.  
  378.  
  379. void CShellApp::init_lance() {
  380.   hts_init();
  381.   htswrap_add("check-link",httrackengine_check);
  382.   htswrap_add("init",httrackengine_init);
  383.   htswrap_add("free",httrackengine_uninit);
  384.   htswrap_add("start",httrackengine_start);
  385.   htswrap_add("end",httrackengine_end);
  386.   htswrap_add("preprocess-html",httrackengine_htmlpreprocess);
  387.   htswrap_add("postprocess-html",httrackengine_htmlpostprocess);
  388.   htswrap_add("check-html",httrackengine_htmlcheck);
  389.   htswrap_add("change-options",httrackengine_chopt);
  390.   htswrap_add("loop",httrackengine_loop);
  391.   htswrap_add("query",httrackengine_query);
  392.   htswrap_add("query2",httrackengine_query2);
  393.   htswrap_add("query3",httrackengine_query3);
  394.   htswrap_add("pause",httrackengine_pause);
  395.   
  396.   termine=termine_requested=shell_terminated=soft_term_requested=0;
  397.   lance();             // Lancer miroir!
  398.   if (fp_debug) {
  399.     fprintf(fp_debug,"Building top index\r\n");
  400.     fflush(fp_debug);
  401.   }
  402.   Build_TopIndex();
  403. }
  404.  
  405. /* sauver profile */
  406. /* ask: demande confirmation, si cela vaut le coup */
  407. int Save_current_profile(int ask) {
  408.   CString winprofile;
  409.   if (ask) {
  410.     if ((dialog0->GetName().IsEmpty()) && (dialog1->m_urls.IsEmpty()))
  411.       return IDNO;
  412.     int r;
  413.     char msg[256];
  414.     sprintf(msg,"%s?\r\n%s",LANG_SAVEPROJECT,dialog0->GetName());
  415.     if ((r=AfxMessageBox(msg,MB_YESNOCANCEL)) != IDYES)
  416.       return r;
  417.   }
  418.   //
  419.   CWaitCursor wait;
  420.   
  421.   // sauver whtt
  422.   {
  423.     CString st=dialog0->GetBasePath()+dialog0->GetName()+".whtt";
  424.     FILE* fp=fopen(st,"wb");
  425.     if (fp) fclose(fp);
  426.   }
  427.   
  428.   // sauver ini
  429.   winprofile=dialog0->GetPath();
  430.   if (winprofile.GetLength()>0)
  431.     if ((winprofile.Right(1)!="/") && (winprofile.Right(1)!="\\"))
  432.       winprofile+="\\";
  433.     winprofile+="hts-cache\\";
  434.     {
  435.       char tempo[HTS_URLMAXSIZE*2];
  436.       int i;
  437.       strcpybuff(tempo,winprofile);
  438.       for(i=0;i<(int)strlen(tempo);i++)
  439.         if (tempo[i]=='\\')
  440.           tempo[i]='/';              
  441.         structcheck(tempo);
  442.     }
  443.     
  444.     winprofile+="winprofile.ini";
  445.     Write_profile(winprofile,0);
  446.     
  447.     // marquer document comme "sauvΘ"
  448.     if (this_CSplitterFrame)
  449.       this_CSplitterFrame->SetSaved();
  450.     
  451.     return IDYES;
  452. }
  453.  
  454. // reprise possible?
  455. int check_continue(char* pathlog) {
  456.   char path_log[256];
  457.   strcpybuff(path_log,pathlog);
  458.   if (strlen(path_log)>0)
  459.     if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  460.       strcatbuff(path_log,"/");
  461.     if (
  462.       fexist(fconcat(path_log,"hts-cache/new.zip"))
  463.       ||
  464.       (fexist(fconcat(path_log,"hts-cache/new.dat"))) && (fexist(fconcat(path_log,"hts-cache/new.ndx")))
  465.       ) {  // il existe dΘja un cache prΘcΘdent.. renommer
  466.       //if (fexist(fconcat(path_log,"hts-cache/doit.log"))) {    // un cache est prΘsent
  467.       return 1;
  468.       //}
  469.     }
  470.     if (
  471.       fexist(fconcat(path_log,"hts-cache/old.zip"))
  472.       ||
  473.       (fexist(fconcat(path_log,"hts-cache/old.dat"))) && (fexist(fconcat(path_log,"hts-cache/old.ndx")))
  474.       ) {  // il existe dΘja un ancien cache prΘcΘdent.. renommer
  475.       return 1;
  476.     }
  477.     AfxMessageBox(LANG(LANG_F2 /*"There is no cache in the directory indicated\nWinHTTrack can not find any interrupted mirror!"*/),MB_OK+MB_ICONSTOP);
  478.     return 0;
  479. }
  480.  
  481.  
  482. void CShellApp::OptPannel() {
  483.   Write_profile("<mem>",0);       // enregistrer profile dans buffer local
  484.   if (maintab->DoModal()==IDCANCEL) {
  485.     Read_profile("<mem>",0);      // restaurer
  486.   }
  487. }
  488.  
  489.  
  490. #define ADD_MIME_IN_COPT(A) \
  491.   if(strlen(maintab->m_option11.m_ext##A)+strlen(maintab->m_option11.m_mime##A)) { \
  492.   ShellOptions->buff_MIME += "--assume "; \
  493.   ShellOptions->buff_MIME += maintab->m_option11.m_ext##A; \
  494.   ShellOptions->buff_MIME += "="; \
  495.   ShellOptions->buff_MIME += maintab->m_option11.m_mime##A; \
  496.   ShellOptions->buff_MIME += " "; \
  497.   } \
  498.   
  499. // parser maintab et calculer options
  500. void compute_options() { 
  501.   CWaitCursor wait;
  502.   
  503.   /* Effacer options */
  504.   if (ShellOptions != NULL) {
  505.     delete ShellOptions;
  506.     ShellOptions = NULL;
  507.   }
  508.   ShellOptions = new CShellOptions();
  509.   /* Effacer options */
  510.   
  511.   // Mode de miroir
  512.   switch(dialog1->m_todo) {
  513.   case CB_ERR: case 0:
  514.     ShellOptions->choixdeb = "w";
  515.     break;
  516.   case 1:
  517.     ShellOptions->choixdeb = "W";
  518.     break;
  519.   case 2:
  520.     ShellOptions->choixdeb = "g";
  521.     break;
  522.   case 3:
  523.     ShellOptions->choixdeb = "Y";
  524.     break;
  525.   case 4:
  526.     ShellOptions->choixdeb = "!";
  527.     break;
  528.   default:
  529.     if (dialog1->m_todo==dialog1->LAST_ACTION)
  530.       ShellOptions->choixdeb = "i";    // reprise
  531.     else
  532.       ShellOptions->choixdeb = "/";    // reprise cache prioritaire
  533.     break;
  534.   }
  535.   
  536.   // URLS
  537.   ShellOptions->url = dialog1->m_urls;
  538.   StripControls(ShellOptions->url.GetBuffer(0));
  539.   // --- formation du path
  540.   ShellOptions->path = "\"";
  541.   ShellOptions->path += dialog0->GetPath0();
  542.   ShellOptions->path += "\"";
  543.   ShellOptions->path += ",";
  544.   ShellOptions->path += "\"";
  545.   ShellOptions->path += dialog0->GetPath0();
  546.   ShellOptions->path += "\"";
  547.   
  548.   // filelist
  549.   {
  550.     CString st=dialog1->m_filelist;
  551.     st.TrimLeft();
  552.     st.TrimRight();
  553.     ShellOptions->filelist = st;
  554.   }
  555.   
  556.   // stocker Θtat et hh/mm/ss
  557.   ShellOptions->hh = dialog2->m_hh;
  558.   ShellOptions->mm = dialog2->m_mm;
  559.   ShellOptions->ss = dialog2->m_ss;
  560.   if (ShellOptions->hh.GetLength()) {    // heure
  561.     int x,y,z;
  562.     sscanf(ShellOptions->hh.GetBuffer(0),"%d",&x);
  563.     x=min(max(x,0),23);
  564.     ShellOptions->hh.Format("%d",x);
  565.     //
  566.     sscanf(ShellOptions->mm.GetBuffer(0),"%d",&y);
  567.     y=min(max(y,0),59);
  568.     ShellOptions->mm.Format("%d",y);
  569.     //
  570.     sscanf(ShellOptions->ss.GetBuffer(0),"%d",&z);
  571.     z=min(max(z,0),59);
  572.     ShellOptions->ss.Format("%d",z);
  573.     //
  574.     ShellOptions->waittime = "";
  575.     {
  576.       char str[32];
  577.       ShellOptions->waittime = "#u";
  578.       sprintf(str,"%d",x*3600+y*60+z);
  579.       ShellOptions->waittime += str;
  580.     }
  581.   }
  582.   ShellOptions->_RasString = dialog2->RasString;
  583.   ShellOptions->_dial=dialog2->dial;
  584.   
  585.   if (ShellOptions->choixdeb[0]=='/') {
  586.     ShellOptions->cache = "C1";      // cache prio
  587.   } else {
  588.     if(!maintab->m_option3.m_cache) 
  589.       ShellOptions->cache = "C0"; 
  590.     else 
  591.       ShellOptions->cache = "C2";     // cache non prio 
  592.     //ShellOptions->cache[0]='\0'; 
  593.   }
  594.   
  595.   // ne pas recharger fichiers dΘja pris mais effacΘs
  596.   if(maintab->m_option9.m_norecatch) ShellOptions->norecatch = "%n"; else ShellOptions->norecatch = "";
  597.   
  598.   // proxy
  599.   ShellOptions->proxy = maintab->m_option10.m_proxy;
  600.   ShellOptions->port = maintab->m_option10.m_port;
  601.   if (maintab->m_option10.m_ftpprox) 
  602.     ShellOptions->proxyftp = "%f";
  603.   else
  604.     ShellOptions->proxyftp = "%f0";   
  605.   
  606.   //depth
  607.   ShellOptions->depth = maintab->m_option5.m_depth;
  608.   ShellOptions->extdepth = maintab->m_option5.m_depth2;
  609.   
  610.   if(!maintab->m_option9.m_index) ShellOptions->index = "I0"; else ShellOptions->index = ""; 
  611.   if(!maintab->m_option9.m_index2) ShellOptions->index2 = "%I0"; else ShellOptions->index2 = "%I"; 
  612.   if(maintab->m_option2.m_dos) 
  613.     ShellOptions->dos = "L0"; 
  614.   else if(maintab->m_option2.m_iso9660) 
  615.     ShellOptions->dos = "L2"; 
  616.   else 
  617.     ShellOptions->dos = ""; 
  618.   if(maintab->m_option1.m_testall) ShellOptions->testall = "t"; else ShellOptions->testall = ""; 
  619.   if(maintab->m_option1.m_parseall) ShellOptions->parseall = "%P"; else ShellOptions->parseall = "%P0"; 
  620.   if(maintab->m_option1.m_link) ShellOptions->link = "n"; else ShellOptions->link = ""; 
  621.   if(maintab->m_option1.m_htmlfirst) ShellOptions->htmlfirst = "p7"; else ShellOptions->htmlfirst = ""; 
  622.   if(maintab->m_option2.m_errpage) ShellOptions->errpage = "o0"; else ShellOptions->errpage = ""; 
  623.   if(maintab->m_option2.m_external) ShellOptions->external = "x"; else ShellOptions->external = ""; 
  624.   if(maintab->m_option2.m_nopurge) ShellOptions->nopurge = "X0"; else ShellOptions->nopurge = ""; 
  625.   if(maintab->m_option2.m_hidepwd) ShellOptions->hidepwd = "%x"; else ShellOptions->hidepwd = ""; 
  626.   if(maintab->m_option2.m_hidequery) ShellOptions->hidequery = "%q0"; else ShellOptions->hidequery = ""; 
  627.   
  628.   ShellOptions->robots = "";
  629.   if(maintab->m_option8.m_robots==0) ShellOptions->robots = "s0"; 
  630.   else if(maintab->m_option8.m_robots==1) ShellOptions->robots = "s1"; 
  631.   else if(maintab->m_option8.m_robots==2) ShellOptions->robots = "s2"; 
  632.   
  633.   // cookies,checktype,parsejava
  634.   if(maintab->m_option8.m_cookies==0) ShellOptions->cookies = "b0"; // else ShellOptions->cookies = "b1";
  635.   if (maintab->m_option8.m_checktype>=0)
  636.     ShellOptions->checktype.Format("u%d",maintab->m_option8.m_checktype);
  637.   if(maintab->m_option8.m_parsejava==0) ShellOptions->parsejava = "j0"; // else ShellOptions->cookies = "j1";
  638.   if (maintab->m_option8.m_http10) ShellOptions->http10 = "%h";   // HTTP/1.0 notamment
  639.   if (maintab->m_option8.m_toler)  ShellOptions->toler = "%B";    // tolerent
  640.   if (maintab->m_option8.m_updhack)  ShellOptions->updhack = "%s";    // update hack
  641.   if (maintab->m_option8.m_urlhack)  ShellOptions->urlhack = "%u";    // URL hack
  642.   else                               ShellOptions->urlhack = "%u0";
  643.   
  644.   // store all in cache,logtype
  645.   if(maintab->m_option9.m_Cache2!=0) ShellOptions->Cache2 = "k";
  646.   if(maintab->m_option9.m_logtype==1) ShellOptions->logtype = "z";
  647.   else if(maintab->m_option9.m_logtype==2) ShellOptions->logtype = "Z";
  648.   if (maintab->m_option3.m_windebug) ShellOptions->logtype += "%H";      // debug headers
  649.   
  650.   ShellOptions->build = "";
  651.   if      (maintab->m_option2.m_build==0) ShellOptions->build = "N0";
  652.   else if (maintab->m_option2.m_build==1) ShellOptions->build = "N1";
  653.   else if (maintab->m_option2.m_build==2) ShellOptions->build = "N2";
  654.   else if (maintab->m_option2.m_build==3) ShellOptions->build = "N3";
  655.   else if (maintab->m_option2.m_build==4) ShellOptions->build = "N4";
  656.   else if (maintab->m_option2.m_build==5) ShellOptions->build = "N5";
  657.   else if (maintab->m_option2.m_build==6) ShellOptions->build = "N100";
  658.   else if (maintab->m_option2.m_build==7) ShellOptions->build = "N101";
  659.   else if (maintab->m_option2.m_build==8) ShellOptions->build = "N102";
  660.   else if (maintab->m_option2.m_build==9) ShellOptions->build = "N103";
  661.   else if (maintab->m_option2.m_build==10) ShellOptions->build = "N104";
  662.   else if (maintab->m_option2.m_build==11) ShellOptions->build = "N105";
  663.   else if (maintab->m_option2.m_build==12) ShellOptions->build = "N99";
  664.   else if (maintab->m_option2.m_build==13) ShellOptions->build = "N199";
  665.   else if (maintab->m_option2.m_build==14) {
  666.     ShellOptions->build = "-N \"";
  667.     ShellOptions->build += maintab->m_option2.Bopt.m_BuildString;
  668.     ShellOptions->build += "\"";
  669.   }
  670.   
  671.   ShellOptions->filtre = "";
  672.   if      (maintab->m_option3.m_filter==0) ShellOptions->filtre = "p0";
  673.   else if (maintab->m_option3.m_filter==1) ShellOptions->filtre = "p1";
  674.   else if (maintab->m_option3.m_filter==2) ShellOptions->filtre = "p2";
  675.   else if (maintab->m_option3.m_filter==3) {    /* default */
  676.     if(!maintab->m_option1.m_htmlfirst) ShellOptions->filtre = "p3";
  677.   }
  678.   else if (maintab->m_option3.m_filter==4) ShellOptions->filtre = "p7";
  679.   //
  680.   if      (maintab->m_option3.m_travel==0) ShellOptions->filtre += "S";
  681.   else if (maintab->m_option3.m_travel==1) ShellOptions->filtre += "D";
  682.   else if (maintab->m_option3.m_travel==2) ShellOptions->filtre += "U";
  683.   else if (maintab->m_option3.m_travel==3) ShellOptions->filtre += "B";
  684.   //
  685.   if      (maintab->m_option3.m_travel2==0) ShellOptions->filtre += "a";
  686.   else if (maintab->m_option3.m_travel2==1) ShellOptions->filtre += "d";
  687.   else if (maintab->m_option3.m_travel2==2) ShellOptions->filtre += "l";
  688.   else if (maintab->m_option3.m_travel2==3) ShellOptions->filtre += "e";
  689.   //
  690.   if      (maintab->m_option3.m_travel3==0) ShellOptions->filtre += "K0";
  691.   else if (maintab->m_option3.m_travel3==1) ShellOptions->filtre += "K";
  692.   else if (maintab->m_option3.m_travel3==2) ShellOptions->filtre += "K3";
  693.   else if (maintab->m_option3.m_travel3==3) ShellOptions->filtre += "K4";
  694.  
  695.   if (maintab->m_option9.m_logf) ShellOptions->log = "f2"; else ShellOptions->log = "Q"; 
  696.   
  697.   if(maintab->m_option5.m_sizemax!=""){
  698.     ShellOptions->max = "M";
  699.     ShellOptions->max += maintab->m_option5.m_sizemax;
  700.   } else ShellOptions->max = "";
  701.   
  702.   if(maintab->m_option5.m_pausebytes!=""){
  703.     ShellOptions->frag = "G";
  704.     ShellOptions->frag += maintab->m_option5.m_pausebytes;
  705.   } else ShellOptions->frag = "";
  706.   
  707.   
  708.   if(maintab->m_option5.m_maxhtml!="" || maintab->m_option5.m_othermax!="" ){
  709.     ShellOptions->maxfile = "m";
  710.     if(maintab->m_option5.m_othermax!="") ShellOptions->maxfile += maintab->m_option5.m_othermax;
  711.     else ShellOptions->maxfile += "0";
  712.     if(maintab->m_option5.m_maxhtml!="") {ShellOptions->maxfile += ",";ShellOptions->maxfile += maintab->m_option5.m_maxhtml;}
  713.     else {ShellOptions->maxfile += ",";ShellOptions->maxfile += "0";}
  714.   } else ShellOptions->maxfile = "";
  715.   
  716.   if(strcmp(maintab->m_option4.m_connexion,"")!=0){
  717.     ShellOptions->conn = "c";
  718.     ShellOptions->conn += maintab->m_option4.m_connexion;
  719.   } else ShellOptions->conn = "";
  720.   
  721.   if(strcmp(maintab->m_option4.m_timeout,"")!=0){
  722.     ShellOptions->time = "T";
  723.     ShellOptions->time += maintab->m_option4.m_timeout;
  724.   } else ShellOptions->time = "";
  725.   
  726.   // quitter host si timeout ou rate out
  727.   ShellOptions->hostquit = "";
  728.   {
  729.     int a=0;
  730.     if (maintab->m_option4.m_remt)
  731.       a+=1;
  732.     if (maintab->m_option4.m_rems)
  733.       a+=2;
  734.     ShellOptions->hostquit.Format("H%d",a);
  735.   }
  736.  
  737.   // Keep-Alive
  738.   if (maintab->m_option4.m_ka) {
  739.     ShellOptions->ka = "%k";
  740.   } else {
  741.     ShellOptions->ka = "%k0";
  742.   }
  743.  
  744.   
  745.   //--> max time
  746.   if(strcmp(maintab->m_option5.m_maxtime,"")!=0){
  747.     ShellOptions->maxtime = "E";
  748.     ShellOptions->maxtime += maintab->m_option5.m_maxtime;
  749.   } else ShellOptions->maxtime = "";
  750.   
  751.   //--> max rate
  752.   if(strcmp(maintab->m_option5.m_maxrate,"")!=0){
  753.     ShellOptions->maxrate = "A";
  754.     ShellOptions->maxrate += maintab->m_option5.m_maxrate;
  755.   } else ShellOptions->maxrate = "";
  756.   
  757.   if(strcmp(maintab->m_option5.m_maxconn,"")!=0){
  758.     ShellOptions->maxconn = "%c";
  759.     ShellOptions->maxconn += maintab->m_option5.m_maxconn;
  760.   } else ShellOptions->maxconn = "";
  761.   
  762.   if(strcmp(maintab->m_option5.m_maxlinks,"")!=0){
  763.     ShellOptions->maxlinks = "#L";
  764.     ShellOptions->maxlinks += maintab->m_option5.m_maxlinks;
  765.   } else ShellOptions->maxlinks = "";
  766.   
  767.   if(strcmp(maintab->m_option4.m_rate,"")!=0){
  768.     ShellOptions->rate = "J";
  769.     ShellOptions->rate += maintab->m_option4.m_rate;
  770.   } else ShellOptions->rate = "";
  771.   
  772.   if(strcmp(maintab->m_option6.m_user,"")!=0){
  773.     ShellOptions->user = "\"";
  774.     ShellOptions->user += maintab->m_option6.m_user;
  775.     ShellOptions->user += "\"";
  776.   } else ShellOptions->user = "";
  777.   
  778.   if(strcmp(maintab->m_option6.m_footer,"")!=0){
  779.     ShellOptions->footer = "\"";
  780.     ShellOptions->footer += maintab->m_option6.m_footer;
  781.     ShellOptions->footer += "\"";
  782.   } else ShellOptions->footer = "";
  783.   
  784.   if(strcmp(maintab->m_option4.m_retry,"")!=0){
  785.     ShellOptions->retry = "R";
  786.     ShellOptions->retry += maintab->m_option4.m_retry;
  787.   } else ShellOptions->retry = "";
  788.   
  789.   if(strcmp(maintab->m_option7.m_url2,"")!=0){
  790.     ShellOptions->buff_filtres = maintab->m_option7.m_url2;
  791.   } else ShellOptions->buff_filtres = "";
  792.   
  793.   
  794.   // MIME
  795.   ShellOptions->buff_MIME = "";
  796.   ADD_MIME_IN_COPT(1)
  797.     ADD_MIME_IN_COPT(2)
  798.     ADD_MIME_IN_COPT(3)
  799.     ADD_MIME_IN_COPT(4)
  800.     ADD_MIME_IN_COPT(5)
  801.     ADD_MIME_IN_COPT(6)
  802.     ADD_MIME_IN_COPT(7)
  803.     ADD_MIME_IN_COPT(8)
  804.     
  805.     /* autres options: RAS */
  806.     if (dialog2->m_rasdisc)
  807.       disconnect=1;     /* dΘconnexion α la fin */
  808.     else
  809.       disconnect=0;
  810.  
  811.     /* autres options: Shutdown */
  812.     if (dialog2->m_rasshut)
  813.       shutdown_pc=1;     /* Θtendre α la fin */
  814.     else
  815.       shutdown_pc=0;
  816. }
  817.  
  818. /* From MSDN: */
  819. void CALLBACK
  820. MessageBoxTimer(HWND hwnd, UINT uiMsg, UINT idEvent, DWORD dwTime)
  821. {
  822.   PostQuitMessage(0);
  823. }
  824. UINT
  825. TimedMessageBox(
  826.                 HWND hwndParent,
  827.                 LPCTSTR ptszMessage,
  828.                 LPCTSTR ptszTitle,
  829.                 UINT flags,
  830.                 DWORD dwTimeout)
  831. {
  832.   UINT idTimer;
  833.   UINT uiResult;
  834.   MSG msg;
  835.  
  836.   /*
  837.   *  Set a timer to dismiss the message box.
  838.   */ 
  839.   idTimer = SetTimer(NULL, 0, dwTimeout, (TIMERPROC)MessageBoxTimer);
  840.  
  841.   uiResult = MessageBox(hwndParent, ptszMessage, ptszTitle, flags);
  842.  
  843.   /*
  844.   *  Finished with the timer.
  845.   */ 
  846.   KillTimer(NULL, idTimer);
  847.  
  848.   /*
  849.   *  See if there is a WM_QUIT message in the queue. If so,
  850.   *  then you timed out. Eat the message so you don't quit the
  851.   *  entire application.
  852.   */ 
  853.   if (PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE)) {
  854.  
  855.     /*
  856.     *  If you timed out, then return zero.
  857.     */ 
  858.     uiResult = 0;
  859.   }
  860.  
  861.   return uiResult;
  862. }
  863.  
  864. /* From MSDN */
  865. BOOL InitiateSystemShutdownExWithPriv(
  866.   LPTSTR lpMessage,
  867.   DWORD dwTimeout,
  868.   BOOL bForceAppsClosed,
  869.   BOOL bRebootAfterShutdown,
  870.   DWORD dwReason)
  871. {
  872.    HANDLE hToken;              // handle to process token 
  873.    TOKEN_PRIVILEGES tkp;       // pointer to token structure 
  874.  
  875.    BOOL fResult;               // system shutdown flag 
  876.  
  877.    // Get the current process token handle so we can get shutdown 
  878.    // privilege. 
  879.  
  880.    if (!OpenProcessToken(GetCurrentProcess(), 
  881.         TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
  882.       return FALSE; 
  883.  
  884.    // Get the LUID for shutdown privilege. 
  885.  
  886.    LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, 
  887.         &tkp.Privileges[0].Luid); 
  888.  
  889.    tkp.PrivilegeCount = 1;  // one privilege to set    
  890.    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
  891.  
  892.    // Get shutdown privilege for this process. 
  893.  
  894.    AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
  895.       (PTOKEN_PRIVILEGES) NULL, 0); 
  896.  
  897.    // Cannot test the return value of AdjustTokenPrivileges. 
  898.  
  899.    if (GetLastError() != ERROR_SUCCESS) 
  900.       return FALSE; 
  901.  
  902.    // Display the shutdown dialog box and start the countdown. 
  903.  
  904. #if 0
  905.   fResult = InitiateSystemShutdownEx(
  906.     NULL,
  907.     lpMessage,
  908.     dwTimeout,
  909.     bForceAppsClosed,
  910.     bRebootAfterShutdown,
  911.     dwReason
  912.     );
  913. #else
  914. #ifndef EWX_FORCEIFHUNG
  915. #define EWX_FORCEIFHUNG     0x00000010
  916. #endif
  917.    UINT msgRes = TimedMessageBox(NULL, lpMessage, _T("Shutdown"), 
  918.      MB_OKCANCEL  | MB_SYSTEMMODAL | MB_ICONEXCLAMATION, 
  919.      dwTimeout*1000);
  920.      if (msgRes == 0 || msgRes == IDOK) {
  921.        fResult = ExitWindowsEx(EWX_LOGOFF | EWX_POWEROFF | EWX_FORCEIFHUNG, dwReason);
  922.      } else {
  923.        fResult = 0;
  924.      }
  925. #endif
  926.  
  927.    // Disable shutdown privilege.
  928.    tkp.Privileges[0].Attributes = 0; 
  929.    AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
  930.         (PTOKEN_PRIVILEGES) NULL, 0); 
  931.  
  932.    if (!fResult) 
  933.       return FALSE; 
  934.    return TRUE; 
  935. }
  936.  
  937.  
  938. // Les routines α dΘfinir:
  939. int __cdecl httrackengine_check(char* adr,char* fil,int status) {  // appelΘ par le wizard
  940.   return -1;
  941. }
  942. EXECUTION_STATE (WINAPI * SetThreadExecutionState_)(IN EXECUTION_STATE) = NULL;
  943. void __cdecl httrackengine_init() {    // appelΘ lors de l'init de HTTRACK, avant le dΘbut d'un miroir
  944.   // Finished
  945.   PlaySound("MirrorStarted", NULL, SND_ASYNC | SND_NOWAIT | SND_APPLICATION);
  946.  
  947. #if USE_RAS
  948.   has_started=0;
  949. #endif
  950.  
  951.   /* Dynamic SetThreadExecutionState_ */
  952.   if (SetThreadExecutionState_ == NULL) {
  953.     HANDLE handle = LoadLibraryA("Kernel32.dll");
  954.     if (handle != INVALID_HANDLE_VALUE) {
  955.       SetThreadExecutionState_ = (EXECUTION_STATE (__stdcall *)(EXECUTION_STATE)) GetProcAddress((HMODULE)handle, "SetThreadExecutionState");
  956.     }
  957.   }
  958.  
  959.   httrackengine_loop(NULL,0,0,0,0,NULL,0);  // init
  960.   //printf("DEMARRAGE DU MIROIR DETECTE\n");  
  961. }
  962. void __cdecl httrackengine_uninit() {  // appelΘ en fin de miroir (peut Ωtre utile!!!)
  963.   // Finished
  964.   PlaySound("MirrorFinished", NULL, SND_ASYNC | SND_NOWAIT | SND_APPLICATION);
  965.  
  966.  // Disconnect RAS
  967. #if USE_RAS
  968.   if (LibRasUse) {        /* librairie RAS chargΘe */
  969.     if (disconnect) {     /* on doit dΘconnecter */
  970.       if (connected) {    /* on a initiΘ une connexion */
  971.         if (conn)
  972.           LibRas->RasHangUp(conn);
  973.       } else {            /* tout dΘconnecter */
  974.         // On coupe tout (non, pas bourrin)
  975.         DWORD size;
  976.         RASCONN* adr;
  977.         int count=256;
  978.         size = sizeof(RASCONN)*(count+2);
  979.         adr = (RASCONN*) (char*) calloc(size,1);
  980.         if (adr) {
  981.           DWORD ent;
  982.           int i;
  983.           for(i=0;i<count;i++) {
  984.             adr[i].dwSize=sizeof(RASCONN);
  985.             strcpybuff(adr[i].szEntryName,"");
  986.           }
  987.           if (LibRas->RasEnumConnections((RASCONN*) adr,&size,&ent) == 0) {
  988.             for(i=0;i<(int)ent;i++) {
  989.               LibRas->RasHangUp(adr[i].hrasconn);
  990.             }
  991.           }
  992.           free(adr);
  993.         }
  994.         
  995.       }
  996.     }
  997.   }
  998. #endif
  999.  
  1000.   // Shutdown PC
  1001.   if (shutdown_pc) {
  1002.     //ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, 
  1003.     //  SHTDN_REASON_MAJOR_APPLICATION | SHTDN_REASON_MINOR_OTHER);
  1004.     InitiateSystemShutdownExWithPriv( 
  1005.       _T(
  1006.         "WinHTTrack has finished the mirror, the system will soon reboot.\r\n"
  1007.         "Click 'OK' to reboot.\r\n"
  1008.         "** CLICK NOW 'CANCEL' TO CANCEL THE REBOOT! **\r\n"
  1009.       ),
  1010.       6,
  1011.       TRUE /* bForceAppsClosed */,
  1012.       FALSE /* bRebootAfterShutdown */,
  1013.       SHTDN_REASON_MAJOR_APPLICATION | SHTDN_REASON_MINOR_OTHER
  1014.       );
  1015.   }
  1016. }
  1017. int __cdecl httrackengine_start(void* dummy) {   // appelΘ lors du dΘmarrage du miroir (premiΦres requΦtes)
  1018. #if USE_RAS
  1019.   // connexion RAS
  1020.   has_started=1;    // dΘmarrage
  1021.   connected=0;
  1022.   conn = NULL;
  1023.   memset(&SInfo, 0, sizeof(SInfo));
  1024.   if (LibRasUse) {
  1025.     if (ShellOptions->_RasString.GetLength()>0) {    // sΘlection provider
  1026.       if (!LibRas->RasDial(NULL,NULL,&ShellOptions->_dial,NULL,NULL,&conn)) {
  1027.         RASCONNSTATUS status;
  1028.         do {
  1029.           status.dwSize = sizeof(status);
  1030.           LibRas->RasGetConnectStatus(conn,&status);
  1031.           switch(status.rasconnstate) {
  1032.           case RASCS_Connected : 
  1033.             connected=1;
  1034.             break;
  1035.           case RASCS_Disconnected :
  1036.             strcpybuff(connected_err,LANG(LANG_F3 /*"Could not connect to provider"*/));
  1037.             connected=-1;
  1038.             break;
  1039.           }
  1040.         } while(connected==0);
  1041.       } else {
  1042.         strcpybuff(connected_err,LANG(LANG_F3 /*"Could not connect to provider","Impossible d'Θtablir la connexion"*/));
  1043.         connected=-1;
  1044.         //termine=1;
  1045.       }
  1046.     }
  1047.     //
  1048.     if (connected != -1)  // si pas d'erreur RAS
  1049.       return 1;
  1050.     else
  1051.       return 0;
  1052.   } else
  1053.     return 1;
  1054. #else
  1055.   return 1;
  1056. #endif
  1057. }
  1058. int  httrackengine_end() {     // appelΘ lors de la fin du miroir (plus de liens α charger)
  1059.   WHTT_LOCK();
  1060.   termine=1;
  1061.   if (_Cinprogress_inst) {
  1062.     _Cinprogress_inst->EndDialog(IDOK);
  1063.     _Cinprogress_inst=NULL;
  1064.   }
  1065.   WHTT_UNLOCK();
  1066.   return 1;
  1067. }
  1068. int __cdecl httrackengine_htmlpreprocess(char** html,int* len,char* url_adresse,char* url_fichier) {
  1069.   return 1;
  1070. }
  1071. int __cdecl httrackengine_htmlpostprocess(char** html,int* len,char* url_adresse,char* url_fichier) {
  1072.   return 1;
  1073. }
  1074. int __cdecl httrackengine_htmlcheck(char* html,int len,char* url_adresse,char* url_fichier) {    // appelΘ α chaque fois qu'un html doit Ωtre scannΘ (utile pour la prospection mais inutile ici)
  1075.   return 1;
  1076. }
  1077. int __cdecl httrackengine_chopt(void* opt) {
  1078.   return 1;
  1079. }
  1080.  
  1081. // Le routine la plus utile sans doute: elle refresh les tableaux
  1082. // C'est la 2e routine en thread qui assure le refresh graphique
  1083. // (plus efficace)
  1084. // -->C'est elle qui dΘcide de tout arrΩter si elle dΘtecte in termine_request<--
  1085. int __cdecl httrackengine_loop(
  1086.                                void* _back,int back_max,int back_index,
  1087.                                int lien_n,int lien_tot,
  1088.                                int stat_time,
  1089.                                hts_stat_struct* stats) {    // appelΘ α chaque boucle de HTTrack
  1090.   static char s[HTS_URLMAXSIZE*2]="";  // utilisΘ plus loin
  1091.   int stat_written=-1;
  1092.   int stat_updated=-1;
  1093.   int stat_errors=-1;
  1094.   int stat_warnings=-1;
  1095.   int stat_infos=-1;
  1096.   int nbk=-1;
  1097.   LLint nb=-1;
  1098.   int stat_nsocket=-1;
  1099.   LLint stat_bytes=-1;
  1100.   LLint stat_bytes_recv=-1;
  1101.   int irate=-1;
  1102.  
  1103.   /* Mutex */
  1104.   WHTT_LOCK();
  1105.  
  1106.   /* Forces the system to be in the working state by resetting the system idle timer. */
  1107.   if (SetThreadExecutionState_ != NULL)
  1108.     SetThreadExecutionState_(ES_SYSTEM_REQUIRED);
  1109.  
  1110.   if (stats) {
  1111.     stat_written=stats->stat_files;
  1112.     stat_updated=stats->stat_updated_files;
  1113.     stat_errors=stats->stat_errors;
  1114.     stat_warnings=stats->stat_warnings;
  1115.     stat_infos=stats->stat_infos;
  1116.     nbk=stats->nbk;
  1117.     stat_nsocket=stats->stat_nsocket;
  1118.     irate=(int)stats->rate;
  1119.     nb=stats->nb;
  1120.     stat_bytes=stats->nb;
  1121.     stat_bytes_recv=stats->HTS_TOTAL_RECV;
  1122.   }
  1123.   
  1124. #if !SHELL_MULTITHREAD
  1125.   static TStamp last_time;
  1126. #endif
  1127.   int rate;
  1128.   // casts
  1129.   lien_back* back=(lien_back*) _back;
  1130.   //  static int ft=-1;
  1131.   
  1132.   if (back_max == 0) {
  1133. #if !SHELL_MULTITHREAD
  1134.     last_time=0;
  1135. #endif
  1136.     // en cas de manque de time
  1137.     SInfo.refresh=1;
  1138.     SInfo.stat_timestart=time_local();
  1139.     WHTT_UNLOCK();
  1140.     return 1;
  1141.   }
  1142.   
  1143.   if ((termine) || (termine_requested)) {
  1144.     SInfo.refresh=0;      // pas de refresh
  1145.     SInfo.refresh=0;      // pas de refresh
  1146.     termine_requested=1;
  1147.     WHTT_UNLOCK();
  1148.     return 0;
  1149.   }
  1150.   
  1151.   if (stat_written>=0) SInfo.stat_written=stat_written;
  1152.   if (stat_updated>=0) SInfo.stat_updated=stat_updated;
  1153.   if (stat_errors>=0)  SInfo.stat_errors=stat_errors;
  1154.   if (stat_warnings>=0)  SInfo.stat_warnings=stat_warnings;
  1155.   if (stat_infos>=0)  SInfo.stat_infos=stat_infos;
  1156.   
  1157. #if SHELL_MULTITHREAD 
  1158.   //if (((tl-last_time)>=100) || ((tl-last_time)<0)) {   // chaque 100 ms
  1159.   if (SInfo.ask_refresh) {
  1160. #else
  1161.     TStamp tl=0;
  1162.     {
  1163.       time_t tt;
  1164.       struct tm* A;
  1165.       tt=time(NULL);
  1166.       A=localtime(&tt);
  1167.       tl+=A->tm_sec;
  1168.       tl+=A->tm_min*60;
  1169.       tl+=A->tm_hour*60*60;
  1170.       //tl+=A->tm_yday*60*60*24;
  1171.       //tl+=A->tm_year*60*60*24*365;
  1172.       
  1173.       tl*=1000;  // en ms
  1174.       
  1175.       struct _timeb timebuffer;
  1176.       char *timeline;
  1177.       _ftime( &timebuffer );
  1178.       timeline = ctime( & ( timebuffer.time ) );
  1179.       
  1180.       tl+=timebuffer.millitm;    // + ms
  1181.     }
  1182.     if (((tl-last_time)>=HTS_SLEEP_WIN) || ((tl-last_time)<0)) {   // chaque 250 ms
  1183.       last_time=tl;
  1184. #endif
  1185.       //INFILLMEM_LOCKED=1;    // locker interface
  1186.       // OPTI int rate;
  1187.       SInfo.ask_refresh=0;
  1188.       
  1189.       // pour Θviter temps cpu consommΘ trop grand
  1190.       // Sleep(10);
  1191.       
  1192.       // initialiser ft
  1193.       if ((stat_nsocket==-1)) {
  1194.         if (SInfo.ft==-1) {
  1195.           SInfo.ft=stat_time;
  1196.         }
  1197.       }
  1198.       
  1199. #if !SHELL_MULTITHREAD
  1200.       //
  1201.       MSG msg;  
  1202.       if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE )) {     
  1203.         switch (msg.message) {
  1204.         case WM_COMMAND:        
  1205.           switch(msg.wParam) { 
  1206.           case ID_APP_ABOUT: {
  1207.             Cabout about;
  1208.             about.DoModal();                                    }
  1209.             break;
  1210.           case ID_APP_EXIT: case WM_CLOSE :
  1211.             termine_requested=1;
  1212.             break;
  1213.           case  WM_DESTROY: case WM_NCDESTROY: 
  1214.             termine_requested=1;
  1215.             break;
  1216.           }
  1217.           break;        
  1218.           default:
  1219.             DefWindowProc(msg.hwnd,msg.message,msg.wParam,msg.lParam);
  1220.             break;
  1221.         }
  1222.       }
  1223.       //
  1224. #endif
  1225.       
  1226.       // calculer heure si ce n'est dΘja fait
  1227.       if (stat_time<0)
  1228.         SInfo.stat_time=(int) (time_local()-SInfo.stat_timestart);
  1229.       
  1230.       // calculer transfer rate
  1231.       if ((stat_time>0) && (stat_bytes_recv>0))
  1232.         rate=(int)(stat_bytes_recv/stat_time);
  1233.       else
  1234.         rate=0;    // pas d'infos
  1235.       
  1236.       // stocker infos: octets transfΘrΘs, temps, etc.
  1237.       if (stat_bytes>=0) SInfo.stat_bytes=stat_bytes;      // bytes
  1238.       if (stat_time>=0) SInfo.stat_time=stat_time;         // time
  1239.       if (lien_tot>=0) SInfo.lien_tot=lien_tot; // nb liens
  1240.       if (lien_n>=0) SInfo.lien_n=lien_n;       // scanned
  1241.       SInfo.stat_nsocket=stat_nsocket;          // socks
  1242.       if (rate>0)  SInfo.rate=rate;                // rate
  1243.       if (irate>=0) SInfo.irate=irate;             // irate
  1244.       if (SInfo.irate<0) SInfo.irate=SInfo.rate;
  1245.       if (nbk>=0) SInfo.stat_back=nbk;
  1246.       
  1247.       // back: tableau de back_max ΘlΘments de cache
  1248.       // back_max: nombre d'ΘlΘments ^^^^
  1249.       // lien_tot: nombre total de liens traitΘs pour le moment
  1250.       // stat_bytes: octets sauvegardΘs
  1251.       // stat_bytes_recv: octets tΘlΘchargΘs
  1252.       // stat_time: temps en seconde depuis le dΘbut du miroir
  1253.       // stat_nsocket: nombre de sockets connectΘes actuellement
  1254.       // on peut en dΘduire rate=stat_bytes_recv/stat_time
  1255.       
  1256.       // printf("loop.. %d liens, %d octets, %d secondes, %d sockets, TAUX=%d\n",lien_tot,stat_bytes,stat_time,stat_nsocket,rate);
  1257.       
  1258.       // parcourir registre des liens
  1259.       if (back_index>=0) {  // seulement si index passΘ
  1260.         int j,k;
  1261.         int index=0;
  1262.         int ok=0;         // idem
  1263.         int l;            // idem
  1264.         int M=32;         // idem
  1265.         
  1266.         StatsBufferback=(void*) back;
  1267.         StatsBufferback_max=back_max;
  1268.         {
  1269.           int i;
  1270.           for(i=0;i<NStatsBuffer;i++) {
  1271.             strcpybuff(StatsBuffer[i].etat,"");
  1272.             strcpybuff(StatsBuffer[i].nom,"");
  1273.             strcpybuff(StatsBuffer[i].fichier,"");
  1274.             strcpybuff(StatsBuffer[i].url_sav,"");
  1275.             StatsBuffer[i].back=NULL;
  1276.             StatsBuffer[i].size=0;
  1277.             StatsBuffer[i].sizetot=0;
  1278.           }
  1279.         }
  1280.         for(k=0;k<2;k++) {    // 0: lien en cours 1: autres liens
  1281.           for(j=0;(j<3) && (index<NStatsBuffer);j++) {  // passe de prioritΘ
  1282.             int _i;
  1283.             for(_i=0+k;(_i< max(back_max*k,1) ) && (index<NStatsBuffer);_i++) {  // no lien
  1284.               int i=(back_index+_i)%back_max;    // commencer par le "premier" (l'actuel)
  1285.               if (back[i].status>=0) {     // signifie "lien actif"
  1286.                 // int ok=0;  // OPTI
  1287.                 ok=0;
  1288.                 switch(j) {
  1289.                 case 0:     // prioritaire
  1290.                   if ((back[i].status>0) && (back[i].status<99)) {
  1291.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F4 /*"receive","rΘception"*/)); ok=1;
  1292.                   }
  1293.                   break;
  1294.                 case 1:
  1295.                   if (back[i].status==99) {
  1296.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F5 /*"request","requΦte"*/)); ok=1;
  1297.                   }
  1298.                   else if (back[i].status==100) {
  1299.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F6 /*"connect","connexion"*/)); ok=1;
  1300.                   }
  1301.                   else if (back[i].status==101) {
  1302.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F7 /*"search","recherche"*/)); ok=1;
  1303.                   }
  1304.                   else if (back[i].status==1000) {    // ohh le beau ftp
  1305.                     sprintf(StatsBuffer[index].etat,"ftp: %s",back[i].info); ok=1;
  1306.                   }
  1307.                   else if (back[i].status==102) {         // SSL handshake
  1308.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F6 /*"connect","connexion"*/)); ok=1;
  1309.                   }
  1310.                   else if (back[i].status==-103) {         // waiting (keep-alive)
  1311.                     strcpybuff(StatsBuffer[index].etat,LANG(LANG_F8)); ok=1;
  1312.                   }
  1313.                   break;
  1314.                 default:
  1315.                   if (back[i].status==0) {  // prΩt
  1316.                     if ((back[i].r.statuscode==200)) {
  1317.                       strcpybuff(StatsBuffer[index].etat,LANG(LANG_F8 /*"ready","prΩt"*/)); ok=1;
  1318.                     }
  1319.                     else if ((back[i].r.statuscode>=100) && (back[i].r.statuscode<=599)) {
  1320.                       char tempo[256]; tempo[0]='\0';
  1321.                       infostatuscode(tempo,back[i].r.statuscode);
  1322.                       strcpybuff(StatsBuffer[index].etat,tempo); ok=1;
  1323.                     }
  1324.                     else {
  1325.                       strcpybuff(StatsBuffer[index].etat,LANG(LANG_F9 /*"error","erreur"*/)); ok=1;
  1326.                     }
  1327.                   }
  1328.                   break;
  1329.                 }
  1330.                 
  1331.                 if (ok) {
  1332.                   // OPTI int l;
  1333.                   // OPTI int M=32;     // longueur
  1334.                   // OPTI char s[HTS_URLMAXSIZE*2]="";
  1335.                   //
  1336.                   StatsBuffer[index].back=i;        // index pour + d'infos
  1337.                   //
  1338.                   s[0]='\0';
  1339.                   strcpybuff(StatsBuffer[index].url_sav,back[i].url_sav);   // pour cancel
  1340.                   if (strcmp(back[i].url_adr,"file://"))
  1341.                     strcatbuff(s,back[i].url_adr);
  1342.                   else
  1343.                     strcatbuff(s,"localhost");
  1344.                   if (back[i].url_fil[0]!='/')
  1345.                     strcatbuff(s,"/");
  1346.                   strcatbuff(s,back[i].url_fil);
  1347.                   
  1348.                   StatsBuffer[index].fichier[0]='\0';
  1349.                   {
  1350.                     char* a=strrchr(s,'/');
  1351.                     if (a) {
  1352.                       strncatbuff(StatsBuffer[index].fichier,a,200);
  1353.                       *a='\0';
  1354.                     }
  1355.                   }
  1356.                   
  1357.                   if ((l=strlen(s))<MAX_LEN_INPROGRESS)
  1358.                     strcpybuff(StatsBuffer[index].nom,s);
  1359.                   else {
  1360.                     // couper
  1361.                     StatsBuffer[index].nom[0]='\0';
  1362.                     strncatbuff(StatsBuffer[index].nom,s,MAX_LEN_INPROGRESS/2-2);
  1363.                     strcatbuff(StatsBuffer[index].nom,"...");
  1364.                     strcatbuff(StatsBuffer[index].nom,s+l-MAX_LEN_INPROGRESS/2+2);
  1365.                   }
  1366.                   
  1367.                   //if (back[i].url_fil[0]!='/') printf("/");
  1368.                   
  1369.                   if (back[i].r.totalsize>0) {  // taille prΘdΘfinie
  1370.                     StatsBuffer[index].sizetot=back[i].r.totalsize;
  1371.                     StatsBuffer[index].size=back[i].r.size;
  1372.                   } else {  // pas de taille prΘdΘfinie
  1373.                     if (back[i].status==0) {  // prΩt
  1374.                       StatsBuffer[index].sizetot=back[i].r.size;
  1375.                       StatsBuffer[index].size=back[i].r.size;
  1376.                     } else {
  1377.                       StatsBuffer[index].sizetot=8192;
  1378.                       StatsBuffer[index].size=(back[i].r.size % 8192);
  1379.                     }
  1380.                   }
  1381.                   index++;
  1382.                 }
  1383.               }
  1384.             }
  1385.           }
  1386.         }
  1387.     }
  1388.     
  1389. #if SHELL_MULTITHREAD
  1390.     SInfo.refresh=1;     // on signale qu'il faut faire un refresh!
  1391. #else
  1392.     inprogress_refresh();  // tout de suite (non multithread)
  1393. #endif
  1394.     // INFILLMEM_LOCKED=0;    // dΘlocker interface
  1395.   }
  1396.   WHTT_UNLOCK();
  1397.   return (termine==0);
  1398. }
  1399.  
  1400. int inprogress_refresh() {
  1401.   static int toggle=0;
  1402.   // WHTT_LOCK(); // deja fait
  1403.   if ((!termine) && (!termine_requested) && (inprogress->m_hWnd)) {
  1404.     if (SInfo.refresh) {
  1405.       // INREDRAW_LOCKED=1;
  1406.       // REFRESH (si nb de socket==-1 on manage les fenetres)
  1407.       int icn;
  1408.       icn=inprogress->IsIconic();
  1409.       CString lnk;
  1410.       if (SInfo.stat_back)
  1411.         lnk.Format("%d/%d (+%d)",SInfo.lien_n,SInfo.lien_tot-1,SInfo.stat_back);
  1412.       else
  1413.         lnk.Format("%d/%d",SInfo.lien_n,SInfo.lien_tot-1);
  1414.       if (!icn) {
  1415.         int parsing=0;
  1416.         if (!soft_term_requested) {
  1417.           if (!hts_setpause(-1)) {
  1418.             if (!(parsing=hts_is_parsing(-1)))
  1419.               SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F10 /*"Receiving files.","RΘception des fichiers"*/)); 
  1420.             else {
  1421.               switch(hts_is_testing()) {
  1422.               case 0:
  1423.                 SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F11 /*"Parsing HTML file..","Parcours du fichier HTML"*/)); 
  1424.                 break;
  1425.               case 1:
  1426.                 SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F12 /*"Parsing HTML file (testing links)..","Parcours du fichier HTML (test des liens)"*/)); 
  1427.                 break;
  1428.               case 2:
  1429.                 SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F11b)); 
  1430.                 break;
  1431.               case 3:
  1432.                 SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F11c)); 
  1433.                 break;
  1434.               case 4:
  1435.                 SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F15)); 
  1436.                 break;
  1437.               case 5:
  1438.                 SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F15b)); 
  1439.                 break;
  1440.               }
  1441.             }
  1442.           } else {
  1443.             if (((toggle++)/5)%2)
  1444.               SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F13 /*"Paused (select [File]/[Pause transfer] to continue)","Interrompu (choisir [Fichier]/[Interrompre transferts] pour continuer)"*/));
  1445.             else
  1446.               SetDlgItemTextCP(inprogress, IDC_inforun,"");
  1447.           }
  1448.         } else {
  1449.           if (((toggle++)/5)%2)
  1450.             SetDlgItemTextCP(inprogress, IDC_inforun,LANG(LANG_F13b));
  1451.           else
  1452.             SetDlgItemTextCP(inprogress, IDC_inforun,"");
  1453.         }
  1454.         
  1455.         if (SInfo.stat_time>0) {
  1456.           char s[256];
  1457.           qsec2str(s,(TStamp) SInfo.stat_time);
  1458.           SetDlgItemTextCP(inprogress, IDC_i1 ,s);  // time
  1459.         } else
  1460.           SetDlgItemTextCP(inprogress, IDC_i1 , _SN(SInfo.stat_time) );  // time
  1461.         SetDlgItemTextCP(inprogress, IDC_i0 , int2bytes(SInfo.stat_bytes) );  // bytes
  1462.         SetDlgItemTextCP(inprogress, IDC_i2 , lnk);  // scanned
  1463.         if (SInfo.stat_nsocket>0)
  1464.           SetDlgItemTextCP(inprogress, IDC_i3 , _SN(SInfo.stat_nsocket) );  // socks
  1465.         else
  1466.           SetDlgItemTextCP(inprogress, IDC_i3 , "none" );  // wait
  1467.         
  1468.         CString st;
  1469.         st.Format("%s (%s)",int2bytessec(SInfo.irate),int2bytessec(SInfo.rate));
  1470.         SetDlgItemTextCP(inprogress, IDC_i4 , st );  // rate
  1471.         
  1472.         SetDlgItemTextCP(inprogress, IDC_i5 , _SN(SInfo.stat_errors) );
  1473.         SetDlgItemTextCP(inprogress, IDC_i6 , _SN(SInfo.stat_written) );
  1474.         {
  1475.           char tempo[256];
  1476.           int pc=0;
  1477.           if (SInfo.stat_written)
  1478.             pc=(int)((SInfo.stat_updated*100)/(SInfo.stat_written));
  1479.           if (pc)
  1480.             sprintf(tempo,"%d (%d%%)",SInfo.stat_updated,pc);
  1481.           else
  1482.             sprintf(tempo,"%d",SInfo.stat_updated);
  1483.           SetDlgItemTextCP(inprogress, IDC_i7 , tempo );
  1484.         }
  1485.         
  1486.         /*if (!parsing)*/
  1487.         {
  1488.           {
  1489.             int i;
  1490.             for(i=0;i<NStatsBuffer;i++) {
  1491.               if (StatsBuffer[i].sizetot>0) {
  1492.                 TStamp d = ((TStamp) StatsBuffer[i].size * 1000);
  1493.                 d = d / ((TStamp) StatsBuffer[i].sizetot);
  1494.                 StatsBuffer[i].offset = (int) d;
  1495.               } else
  1496.                 StatsBuffer[i].offset = 0;
  1497.             }
  1498.           }
  1499.           
  1500.           if (!parsing)
  1501.             inprogress->m_sl0.SetRange(0,1000);
  1502.           inprogress->m_sl1.SetRange(0,1000);
  1503.           inprogress->m_sl2.SetRange(0,1000);
  1504.           inprogress->m_sl3.SetRange(0,1000);
  1505.           inprogress->m_sl4.SetRange(0,1000);
  1506.           inprogress->m_sl5.SetRange(0,1000);
  1507.           inprogress->m_sl6.SetRange(0,1000);
  1508.           inprogress->m_sl7.SetRange(0,1000);
  1509.           inprogress->m_sl8.SetRange(0,1000);
  1510.           inprogress->m_sl9.SetRange(0,1000);
  1511.           inprogress->m_sl10.SetRange(0,1000);
  1512.           inprogress->m_sl11.SetRange(0,1000);
  1513.           inprogress->m_sl12.SetRange(0,1000);
  1514.           inprogress->m_sl13.SetRange(0,1000);
  1515.           
  1516.           if (!parsing)
  1517.             inprogress->m_sl0.SetPos(StatsBuffer[0].offset);
  1518.           inprogress->m_sl1.SetPos(StatsBuffer[1].offset);
  1519.           inprogress->m_sl2.SetPos(StatsBuffer[2].offset);
  1520.           inprogress->m_sl3.SetPos(StatsBuffer[3].offset);
  1521.           inprogress->m_sl4.SetPos(StatsBuffer[4].offset);
  1522.           inprogress->m_sl5.SetPos(StatsBuffer[5].offset);
  1523.           inprogress->m_sl6.SetPos(StatsBuffer[6].offset);
  1524.           inprogress->m_sl7.SetPos(StatsBuffer[7].offset);
  1525.           inprogress->m_sl8.SetPos(StatsBuffer[8].offset);
  1526.           inprogress->m_sl9.SetPos(StatsBuffer[9].offset);
  1527.           inprogress->m_sl10.SetPos(StatsBuffer[10].offset);
  1528.           inprogress->m_sl11.SetPos(StatsBuffer[11].offset);
  1529.           inprogress->m_sl12.SetPos(StatsBuffer[12].offset);
  1530.           inprogress->m_sl13.SetPos(StatsBuffer[13].offset);
  1531.           
  1532.           // redraw en boucle
  1533.           {
  1534.             int i=0;
  1535.             if (parsing)
  1536.               i++;
  1537.             for( ; i<NStatsBuffer;i++) {
  1538.               CString st;
  1539.               st = StatsBuffer[i].etat;
  1540.               st.Replace("&", "&&");
  1541.               SetWindowTextCP(inprogress->element[0][i], st);
  1542.               st = StatsBuffer[i].nom;
  1543.               st.Replace("&", "&&");
  1544.               SetWindowTextCP(inprogress->element[1][i], st);
  1545.               st = StatsBuffer[i].fichier;
  1546.               st.Replace("&", "&&");
  1547.               SetWindowTextCP(inprogress->element[4][i], st);
  1548.               
  1549.               if ((strlen(StatsBuffer[i].etat)==0) != StatsBuffer[i].actived) {
  1550.                 StatsBuffer[i].actived=!StatsBuffer[i].actived;
  1551.                 if (!StatsBuffer[i].actived)
  1552.                   inprogress->element[3][i]->ModifyStyle(WS_DISABLED,0);
  1553.                 else
  1554.                   inprogress->element[3][i]->ModifyStyle(0,WS_DISABLED);
  1555.                 inprogress->element[3][i]->RedrawWindow();
  1556.               }
  1557.             }
  1558.           }
  1559.           //
  1560.         }
  1561.         /* else*/
  1562.         if (parsing) {  // parsing
  1563.           //
  1564.           inprogress->m_sl0.SetRange(0,100);
  1565.           inprogress->m_sl0.SetPos(parsing);
  1566.           SetWindowTextCP(inprogress->element[0][0], LANG(LANG_F14 /*"scanning","parcours"*/));
  1567.           SetWindowTextCP(inprogress->element[1][0], StatsBuffer[0].nom);
  1568.           SetWindowTextCP(inprogress->element[4][0], "");
  1569.           //inprogress->element[0][1]->SetWindowTextCP(this, );
  1570.         }
  1571.         
  1572.       }
  1573.       {
  1574.         static char last_info[256]="";
  1575.         char info[256];
  1576.         if ((SInfo.stat_nsocket==-1)) {
  1577. #if USE_RAS
  1578.           if (!has_started)
  1579. #endif
  1580.             SetDlgItemTextCP(inprogress, IDC_nm0,LANG(LANG_F15 /*"Waiting for specific hour to start","Attente de l'heure programmΘe pour dΘmarrer"*/));
  1581. #if USE_RAS
  1582.           else
  1583.             SetDlgItemTextCP(inprogress, IDC_nm0,LANG(LANG_F16 /*"Connecting to provider","Connexion au provider"*/));
  1584. #endif
  1585.           inprogress->m_sl0.SetRange(0,SInfo.ft);
  1586.           inprogress->m_sl0.SetPos(SInfo.ft-SInfo.stat_time);  // temps restant
  1587.           // SetDlgItemTextCP(inprogress, IDC_nm1,_SN(ft));
  1588.           if (icn && (!this_CSplitterFrame->iconifie)) {  // minimisΘe mais pas en icone
  1589.             sprintf(info,"[%d s]",SInfo.stat_time);
  1590.           } else {
  1591.             sprintf(info,LANG(LANG_F17 /*"Mirror waiting [%d seconds]","Miroir en attente [%d secondes]"*/),SInfo.stat_time);
  1592.           }
  1593.         } else {
  1594.           if (icn) {  // minimisΘe
  1595.             sprintf(info,"[%s]",lnk);
  1596.           } else {
  1597.             char byteb[256];
  1598.             sprintf(byteb, LLintP, SInfo.stat_bytes);
  1599.             sprintf(info,LANG(LANG_F18),lnk,byteb);
  1600.           }
  1601.         }
  1602.         if (strcmp(info,last_info)) {       /* a changΘ */
  1603.           strcpybuff(last_info,info);           /* recopier */
  1604.           if (this_CSplitterFrame->iconifie)  // minimisΘ icone
  1605.             this_CSplitterFrame->IconChange(last_info);
  1606.           else
  1607.             SetWindowTextCP(GetMainWindow(), last_info);
  1608.         }
  1609.       }  
  1610.       
  1611.       //inprogress->UpdateWindow();
  1612.     } else {
  1613.     }
  1614.   }
  1615.   // WHTT_UNLOCK();
  1616.   return 1;
  1617. }
  1618.  
  1619. /*
  1620. // refresh scan
  1621. int inprogress_refresh_scan() {
  1622. if ((!termine) && (!termine_requested) && (inprogress->m_hWnd)) {
  1623. if (!SInfo.refresh) {
  1624. if (!inprogress->IsIconic()) {
  1625. int n;
  1626. // patch pour le scanning
  1627. if (n=hts_is_parsing()) {
  1628. strcpybuff(StatsBuffer[0].etat,"scanning");
  1629. inprogress->element[0][0]->SetWindowTextCP(this, "scanning");
  1630. StatsBuffer[0].sizetot=100;
  1631. StatsBuffer[0].size=n;
  1632. inprogress->m_sl0.SetRange(0,100);  // progression en % du scanning
  1633. inprogress->m_sl0.SetPos(n);
  1634. //} else {
  1635. //  inprogress->element[0][0]->SetWindowTextCP(this, "...");
  1636. }
  1637. }
  1638. }
  1639. }
  1640. return 1;
  1641. }
  1642. */
  1643.  
  1644. /* Plantages si DoModal() dans un thread != du principal.. passons.. */
  1645. char* __cdecl httrackengine_query(char* question) {
  1646.   strcpybuff(WIZ_question,question);
  1647.   strcpybuff(WIZ_reponse, "");
  1648.   // AfxGetMainWnd()
  1649.   CWnd* wnd = GetMainWindow();
  1650.   if (wnd) {
  1651.     wnd->SendMessage(WM_COMMAND,wm_WizRequest1,0);
  1652.   }
  1653.   return WIZ_reponse;
  1654. }
  1655.  
  1656. char* __cdecl httrackengine_query2(char* question) {
  1657.   strcpybuff(WIZ_question,question);
  1658.   strcpybuff(WIZ_reponse, "");
  1659.   // AfxGetMainWnd()
  1660.   CWnd* wnd = GetMainWindow();
  1661.   if (wnd) {
  1662.     wnd->SendMessage(WM_COMMAND,wm_WizRequest2,0);
  1663.   }
  1664.   return WIZ_reponse;
  1665. }
  1666.  
  1667. char* __cdecl httrackengine_query3(char* question) {
  1668.   strcpybuff(WIZ_question,question);
  1669.   strcpybuff(WIZ_reponse, "");
  1670.   CWnd* wnd = GetMainWindow();
  1671.   if (wnd) {
  1672.     wnd->SendMessage(WM_COMMAND,wm_WizRequest3,0);
  1673.   }
  1674.   return WIZ_reponse;
  1675. }
  1676.  
  1677. void __cdecl httrackengine_pause(char* lockfile) {
  1678.   AfxMessageBox("Engine paused.. click OK to continue!",MB_OK);
  1679.   remove(lockfile);
  1680. }
  1681.  
  1682. // modif RX 10/10/98 pour gestion des , et des tabs
  1683. static void StripControls(char* chaine)
  1684. {
  1685.   for(int i=0 ; chaine[i] != '\0' ; i++)
  1686.   {
  1687.     if(chaine[i]=='\n' || chaine[i]==13 || chaine[i]==9) {
  1688.       chaine[i]=' ';
  1689.     }
  1690.   }
  1691. }
  1692.  
  1693. #if SHELL_MULTITHREAD
  1694.  
  1695. static int __cdecl ExcFilter_(DWORD dwExceptCode, PEXCEPTION_POINTERS pExceptPtrs) {
  1696.   return EXCEPTION_CONTINUE_EXECUTION;
  1697. }                              
  1698.  
  1699. void __cdecl RunBackRobot(void* al_p) {
  1700.   int argc;
  1701.   char** argv;
  1702.  
  1703.   while((!inprogress) && (!termine)) Sleep(10);
  1704.   if (inprogress)
  1705.     while ((!inprogress->m_hWnd) || (termine)) Sleep(10);   // attendre formulaire
  1706.     //Sleep(100);
  1707.     
  1708.     Robot_params* al=(Robot_params*) al_p;
  1709.     argc = al->argc;
  1710.     argv = al->argv;
  1711.     /* launch the engine */
  1712.     hts_init();
  1713.     __try
  1714.     {
  1715.       HTTRACK_result = hts_main(argc,argv);
  1716.     }
  1717.     __except(ExcFilter_(GetExceptionCode(), GetExceptionInformation()))
  1718.     {
  1719.       HTTRACK_result = -1;
  1720.     }
  1721.     /* clear all vars */
  1722.     WHTT_LOCK();
  1723.     termine=1;
  1724.     WHTT_UNLOCK();
  1725.     htsthread_wait_n(1);
  1726.     hts_uninit();
  1727. }
  1728. #endif
  1729.  
  1730. // modifs RX 10/10/98: gestion des ,
  1731. CString change(char* chaine,char c) {
  1732.   int comma=1; int first=1;
  1733.   CString chaine1;
  1734.   for(int i=0;i < (int) strlen(chaine);i++) {
  1735.     switch(chaine[i]) {
  1736.     case 10: case 13: case 9: case ' ': case ',':
  1737.       comma=1; 
  1738.       break;
  1739.     default:
  1740.       if (comma) {
  1741.         if (!first) chaine1 +=' ';
  1742.         else first=0; 
  1743.         chaine1  +=c; 
  1744.         comma=0;
  1745.       }
  1746.       chaine1 += chaine[i]; 
  1747.       break;
  1748.     }
  1749.   }
  1750.   return chaine1;
  1751. }
  1752.  
  1753.  
  1754. // Lancement
  1755. void lance(void) {
  1756.   char **argv;
  1757.   int argvAlloc = 1024;
  1758.   int argc=1;
  1759.   int g=0;
  1760.   int i =0;
  1761.   
  1762.   //
  1763.   if (fp_debug) {
  1764.     fprintf(fp_debug,"Building command line\r\n");
  1765.     fflush(fp_debug);
  1766.   }
  1767.   //
  1768.   ShellOptions->LINE = "";
  1769.   ShellOptions->LINE = "-";
  1770.   if (ShellOptions->choixdeb[0]!='W')
  1771.     ShellOptions->LINE += "q";         // quiet
  1772.   
  1773.   if (ShellOptions->choixdeb[0]=='/')
  1774.     ShellOptions->LINE += "i";
  1775.   else if (ShellOptions->choixdeb[0]!='!')
  1776.     ShellOptions->LINE += ShellOptions->choixdeb;
  1777.   // option de profondeur
  1778.   if(strcmp(ShellOptions->depth,"")!=0) { 
  1779.     ShellOptions->LINE += "r";
  1780.     ShellOptions->LINE += ShellOptions->depth;
  1781.   }
  1782.   if(strcmp(ShellOptions->extdepth,"")!=0) { 
  1783.     ShellOptions->LINE += "%e";
  1784.     ShellOptions->LINE += ShellOptions->extdepth;
  1785.   }
  1786.   if(strcmp(ShellOptions->cache,"")!=0) ShellOptions->LINE += ShellOptions->cache;
  1787.   if(strcmp(ShellOptions->norecatch,"")!=0) ShellOptions->LINE += ShellOptions->norecatch;
  1788.   if(strcmp(ShellOptions->testall,"")!=0) ShellOptions->LINE += ShellOptions->testall;
  1789.   if(strcmp(ShellOptions->parseall,"")!=0) ShellOptions->LINE += ShellOptions->parseall;
  1790.   if(strcmp(ShellOptions->link,"")!=0) ShellOptions->LINE += ShellOptions->link;
  1791.   if(strcmp(ShellOptions->external,"")!=0) ShellOptions->LINE += ShellOptions->external;
  1792.   if(strcmp(ShellOptions->nopurge,"")!=0) ShellOptions->LINE += ShellOptions->nopurge;
  1793.   if(strcmp(ShellOptions->hidepwd,"")!=0) ShellOptions->LINE += ShellOptions->hidepwd;
  1794.   if(strcmp(ShellOptions->hidequery,"")!=0) ShellOptions->LINE += ShellOptions->hidequery;
  1795.   if(strcmp(ShellOptions->robots,"")!=0) ShellOptions->LINE += ShellOptions->robots;
  1796.   if(strcmp(ShellOptions->cookies,"")!=0) ShellOptions->LINE += ShellOptions->cookies;
  1797.   if(strcmp(ShellOptions->checktype,"")!=0) ShellOptions->LINE += ShellOptions->checktype;
  1798.   if(strcmp(ShellOptions->parsejava,"")!=0) ShellOptions->LINE += ShellOptions->parsejava;
  1799.   if(strcmp(ShellOptions->Cache2,"")!=0) ShellOptions->LINE += ShellOptions->Cache2;
  1800.   if(strcmp(ShellOptions->logtype,"")!=0) ShellOptions->LINE += ShellOptions->logtype;
  1801.   if (ShellOptions->http10.GetLength()) ShellOptions->LINE += ShellOptions->http10;
  1802.   if (ShellOptions->toler.GetLength()) ShellOptions->LINE += ShellOptions->toler;
  1803.   if (ShellOptions->updhack.GetLength()) ShellOptions->LINE += ShellOptions->updhack;
  1804.   if (ShellOptions->urlhack.GetLength()) ShellOptions->LINE += ShellOptions->urlhack;
  1805.   
  1806.   // si get, ne pas faire
  1807.   if (strcmp(ShellOptions->choixdeb,"g")!=0) {
  1808.     if(ShellOptions->build[0]=='-') {
  1809.       ShellOptions->LINE += " ";
  1810.       ShellOptions->LINE += ShellOptions->build;
  1811.       ShellOptions->LINE += " -";
  1812.     } else if (strcmp(ShellOptions->build,"")!=0) ShellOptions->LINE += ShellOptions->build;
  1813.   }
  1814.   ShellOptions->LINE += ShellOptions->dos;
  1815.   ShellOptions->LINE += ShellOptions->index;
  1816.   ShellOptions->LINE += ShellOptions->index2;
  1817.   ShellOptions->LINE += ShellOptions->htmlfirst;
  1818.   ShellOptions->LINE += ShellOptions->filtre;
  1819.   ShellOptions->LINE += ShellOptions->max;
  1820.   ShellOptions->LINE += ShellOptions->frag;
  1821.   ShellOptions->LINE += ShellOptions->maxfile;
  1822.   ShellOptions->LINE += ShellOptions->conn;
  1823.   ShellOptions->LINE += ShellOptions->time;
  1824.   ShellOptions->LINE += ShellOptions->rate;
  1825.   ShellOptions->LINE += ShellOptions->retry;
  1826.   ShellOptions->LINE += ShellOptions->hostquit;
  1827.   ShellOptions->LINE += ShellOptions->ka;
  1828.   ShellOptions->LINE += ShellOptions->log;
  1829.   ShellOptions->LINE += ShellOptions->errpage;
  1830.   //-->
  1831.   ShellOptions->LINE += ShellOptions->waittime;
  1832.   ShellOptions->LINE += ShellOptions->maxtime;
  1833.   ShellOptions->LINE += ShellOptions->maxrate;
  1834.   ShellOptions->LINE += ShellOptions->maxconn;
  1835.   ShellOptions->LINE += ShellOptions->maxlinks;
  1836.   ShellOptions->LINE += ShellOptions->proxyftp;  
  1837.   ShellOptions->LINE += "#f";  // flush
  1838.   
  1839.   if (strcmp(ShellOptions->user,"")!=0) {ShellOptions->LINE += " ";ShellOptions->LINE += "-F";ShellOptions->LINE += " ";ShellOptions->LINE += ShellOptions->user;}
  1840.   if (strcmp(ShellOptions->footer,"")!=0) {ShellOptions->LINE += " ";ShellOptions->LINE += "-%F";ShellOptions->LINE += " ";ShellOptions->LINE += ShellOptions->footer;}
  1841.   
  1842.   if ((int)ShellOptions->proxy.GetLength()>0) {
  1843.     ShellOptions->LINE += " -P ";
  1844.     ShellOptions->LINE += ShellOptions->proxy;
  1845.     ShellOptions->LINE += ":";
  1846.     ShellOptions->LINE += ShellOptions->port;
  1847.   }
  1848.   
  1849.   if (strnotempty(LANGUAGE_ISO)) {
  1850.     ShellOptions->LINE += " -%l \"";
  1851.     ShellOptions->LINE += LANGUAGE_ISO;
  1852.     if (LANGUAGE_ISO != "en")
  1853.       ShellOptions->LINE += ", en";
  1854.     ShellOptions->LINE += ", *\"";
  1855.   }
  1856.   
  1857.   // mode spider, mettre aprΦs options
  1858.   if (ShellOptions->choixdeb[0]=='!') {
  1859.     ShellOptions->LINE += " --testlinks";
  1860.   } else if (ShellOptions->choixdeb[0]=='Y') {
  1861.     ShellOptions->LINE += " --mirrorlinks";
  1862.   }
  1863.   
  1864.   // URLs!!
  1865.   ShellOptions->LINE += " ";
  1866.   ShellOptions->LINE += ShellOptions->url;
  1867.   
  1868.   // file list
  1869.   if ((int) ShellOptions->filelist.GetLength()>0) {
  1870.     ShellOptions->LINE += " -%L \"";
  1871.     ShellOptions->LINE += ShellOptions->filelist;
  1872.     ShellOptions->LINE += "\"";
  1873.   }
  1874.   
  1875.   // chemins
  1876.   if(ShellOptions->path != "") {
  1877.     ShellOptions->LINE += " ";
  1878.     ShellOptions->LINE += "-O";
  1879.     ShellOptions->LINE += " ";
  1880.     ShellOptions->LINE += ShellOptions->path;
  1881.   }
  1882.   
  1883.   // buffer -> les + et -
  1884.   if(strcmp(ShellOptions->buff_filtres,"")!=0) {
  1885.     //if(strcmp(diafiltre.m_url2 ,"")!=0) {
  1886.     ShellOptions->LINE += " ";
  1887.     ShellOptions->LINE += ShellOptions->buff_filtres ;
  1888.   }
  1889.   
  1890.   // --assume
  1891.   if (strnotempty(ShellOptions->buff_MIME)) {
  1892.     ShellOptions->LINE += " ";
  1893.     ShellOptions->LINE += ShellOptions->buff_MIME ;
  1894.   }
  1895.   
  1896.   // ---
  1897.   
  1898.   //
  1899.   if (fp_debug) {
  1900.     fprintf(fp_debug,"Cleaning up command line and counting parameters\r\n");
  1901.     fflush(fp_debug);
  1902.   }
  1903.   //
  1904.   // Θpurer cr,lf,tab - double espace -> espace
  1905.   {
  1906.     char *a;
  1907.     while(a=strchr(ShellOptions->LINE,9)) *a=' ';
  1908.     while(a=strchr(ShellOptions->LINE,10)) *a=' ';
  1909.     while(a=strchr(ShellOptions->LINE,13)) *a=' ';
  1910.   }
  1911.   
  1912.   ShellOptions->LINE_back = ShellOptions->LINE;
  1913.   
  1914.   // couper en morceaux
  1915.   {
  1916.     char* p=ShellOptions->LINE.GetBuffer(0);
  1917.     argv = (char**) malloct(argvAlloc * sizeof(char*));
  1918.     argv[0]="winhttrack";
  1919.     do {
  1920.       if (argc >= argvAlloc) {
  1921.         argvAlloc *= 2;
  1922.         argv = (char**) realloct(argv, argvAlloc * sizeof(char*));
  1923.         assertf(argv != NULL);
  1924.       }
  1925.       argv[argc++]=p;
  1926.       p=next_token(p,0);    // prochain token
  1927.       if (p) {
  1928.         *p=0;    // octet nul (tableau)
  1929.         p++;
  1930.       }            
  1931.     } while(p!=NULL);
  1932.   }
  1933.   
  1934.   //
  1935.   if (fp_debug) {
  1936.     fprintf(fp_debug,"Checking doit.log\r\n");
  1937.     fflush(fp_debug);
  1938.   }
  1939.   //
  1940.   // Ok, on lance!
  1941.   if(!termine) {
  1942.     int result=0;
  1943.     {
  1944.       char path_log[HTS_URLMAXSIZE*2];
  1945.       strcpybuff(path_log,CShellApp_app->end_path_complete);
  1946.       if (strlen(path_log)>0)
  1947.         if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  1948.           strcatbuff(path_log,"/");
  1949.         
  1950.         // on efface le doit.log, pour annuler les parametres anciens et en redΘfinir de nouveaux
  1951.         // c'est ici une logique qui diffΦre de la version en ligne de commande
  1952.         if (fexist(fconcat(path_log,"hts-cache/new.zip"))
  1953.           || fexist(fconcat(path_log,"hts-cache/new.ndx"))
  1954.           ) {    // un cache est prΘsent
  1955.           if (fexist(fconcat(path_log,"hts-cache/doit.log")))
  1956.             remove(fconcat(path_log,"hts-cache/doit.log"));
  1957.           FILE* fp=fopen(fconcat(path_log,"hts-cache/doit.log"),"wb");
  1958.           if (fp) fclose(fp);
  1959.         }
  1960.         //}
  1961.     }
  1962.     
  1963.     
  1964.     // ---
  1965.     // LANCER LE MIROIR
  1966.     // ---
  1967.     //
  1968.     if (fp_debug) {
  1969.       fprintf(fp_debug,"Ready to call httrack engine, launching threads\r\n");
  1970.       fflush(fp_debug);
  1971.     }
  1972.     //
  1973. #if SHELL_MULTITHREAD
  1974.     Robot_params al;
  1975.     al.argc=argc;
  1976.     al.argv=argv;
  1977.     (void)hts_newthread( RunBackRobot     , 0, (void*) &al);
  1978.     //_beginthread( RunBackRobot     , 0, (void*) &al);
  1979.     //_beginthread( RefreshBackRobot , 0, NULL);
  1980.     
  1981.     //
  1982.     if (fp_debug) {
  1983.       fprintf(fp_debug,"Threads launched, displaying main dialog\r\n");
  1984.       fflush(fp_debug);
  1985.     }
  1986.     //
  1987.     // domodal du refresh
  1988.     /* XXC A SUPPRIMER */
  1989.     while(!termine) {
  1990.       Sleep(100);
  1991.     }
  1992.     //inprogress->DoModal();
  1993.     WHTT_LOCK();
  1994.     shell_terminated=1;
  1995.     result=HTTRACK_result;
  1996.     termine=1;  
  1997.     WHTT_UNLOCK();
  1998.     //
  1999.     if (fp_debug) {
  2000.       fprintf(fp_debug,"Main dialog exited\r\n");
  2001.       fflush(fp_debug);
  2002.     }
  2003.     //
  2004.     
  2005.     // non multithread
  2006. #else
  2007. #error "Non supportΘ"
  2008. #endif
  2009.  
  2010.     /* Aborted mirror or finished? */
  2011.     {
  2012.       char path_log[HTS_URLMAXSIZE*2];
  2013.       strcpybuff(path_log,CShellApp_app->end_path_complete);
  2014.       if (strlen(path_log)>0)
  2015.         if ((path_log[strlen(path_log)-1]!='/') && (path_log[strlen(path_log)-1]!='\\'))
  2016.           strcatbuff(path_log,"/");
  2017.         if (soft_term_requested || termine_requested) {
  2018.           FILE* fp=fopen(fconcat(path_log,"hts-cache/interrupted.lock"),"wb");
  2019.           if (fp)
  2020.             fclose(fp);
  2021.         } else
  2022.           remove(fconcat(path_log,"hts-cache/interrupted.lock"));
  2023.     }
  2024.     
  2025.     //SetForegroundWindow();   // yop en premier plan!
  2026.     //
  2027.     if (fp_debug) {
  2028.       fprintf(fp_debug,"Displaying end dialog\r\n");
  2029.       fflush(fp_debug);
  2030.     }
  2031.     //
  2032.     /* New pannel */
  2033.     if (result) {      // erreur?
  2034.       strcpybuff(end_mirror_msg,LANG(LANG_F19 /*"A problem occured during the mirror\n  \"","Un problΦme est survenu pendant le miroir\n  \""*/));
  2035.       strcatbuff(end_mirror_msg,"\"");
  2036.       if (result != -1) {
  2037.         strcatbuff(end_mirror_msg,hts_errmsg());
  2038.       } else {
  2039.         strcatbuff(end_mirror_msg, "The engine unexpectedly crashed.");
  2040.       }
  2041.       strcatbuff(end_mirror_msg,"\"");
  2042.       strcatbuff(end_mirror_msg,LANG(LANG_F20 /*"\" \nDuring:\n  ","\" \nDurant:\n  "*/));
  2043.       strcatbuff(end_mirror_msg,"\"");
  2044.       strcatbuff(end_mirror_msg,ShellOptions->LINE_back);
  2045.       strcatbuff(end_mirror_msg,"\"");
  2046.       strcatbuff(end_mirror_msg,LANG(LANG_F21 /*"\nSee the log file if necessary.\n\nClick OK to quit WinHTTrack.\n\nThanks for using WinHTTrack!","\nVoir le fichier log au besoin\n\nCliquez sur OK pour quitter WinHTTrack\n\nMerci d'utiliser WinHTTrack."*/));
  2047.       //AfxMessageBox(s,MB_OK+MB_ICONINFORMATION);
  2048.     } else {
  2049.       strcpybuff(end_mirror_msg,LANG(LANG_F22 /*"The mirror is finished.\nClick OK to quit WinHTTrack.\nSee log file(s) if necessary to ensure that everything is OK.\n\nThanks for using WinHTTrack!","Le miroir est terminΘ\nCliquez sur OK pour quitter WinHTTrack\nVoir au besoin les fichiers d'audit pour vΘrifier que tout s'est bien passΘ\n\nMerci d'utiliser WinHTTrack!"*/));
  2050.       //AfxMessageBox("The mirror is finished.\nClic OK to quit WinHTTrack.\nSee log file(s) if necessary to ensure that everything is OK.\n\nThanks for using WinHTTrack!",MB_OK+MB_ICONINFORMATION);
  2051.       //        ShellExecute(0,"open",,"","",);
  2052.     }
  2053. #if USE_RAS
  2054.     // erreur ras
  2055.     if (connected == -1)
  2056.       if ((int) strlen(connected_err) > 0)
  2057.         strcpybuff(end_mirror_msg,connected_err);
  2058. #endif
  2059.       {
  2060.         char pathlog[HTS_URLMAXSIZE*2];
  2061.         strcpybuff(pathlog,dialog0->GetPath());
  2062.         Ciplog form;
  2063.         if (strlen(pathlog)>0)
  2064.           if ((pathlog[strlen(pathlog)-1]!='/') && (pathlog[strlen(pathlog)-1]!='\\'))
  2065.             strcatbuff(pathlog,"/");
  2066.           // fichier log existe ou on est tΘlΘcommandΘ par un !
  2067.           if ( (fsize(fconcat(pathlog,"hts-err.txt")))>0) {
  2068.             strcatbuff(end_mirror_msg,LANG(LANG_F23 /*"\n\nTip: Click [View log file] to see warning or error messages","\n\nConseil: [Voir fichiers log] pour voir les erreurs et messages"*/));
  2069.           }
  2070.       }
  2071.       //this_Cinfoend->m_infoend = msg;
  2072.       inprogress->SendMessage(WM_USER + 4);      // avertir
  2073.       if (fp_debug) {
  2074.         fprintf(fp_debug,"DoModal end dialog, waiting\r\n");
  2075.         fflush(fp_debug);
  2076.       }
  2077.       /*
  2078.       if (info.DoModal() == IDC_NewProject) {     // relancer programme!
  2079.       // copie de onnewproject() de wid1::
  2080.       CWinApp* pApp = AfxGetApp();
  2081.       CString name = pApp->m_pszHelpFilePath;
  2082.       name=name.Left(name.GetLength()-4);
  2083.       name += ".EXE";
  2084.       ShellExecute(NULL,"open",name,"","",SW_RESTORE);    
  2085.       }
  2086.       */
  2087.       if (fp_debug) {
  2088.         fprintf(fp_debug,"Final info OK, leaving..\r\n");
  2089.         fflush(fp_debug);
  2090.       }
  2091.   }
  2092.   else {
  2093.   }
  2094.  
  2095.   if (argv != NULL)
  2096.     freet(argv);
  2097.   
  2098. }
  2099.  
  2100. // int LANG_T(int);
  2101. // char* LANG(char* english,char* francais);
  2102.  
  2103.  
  2104. /* interface lang - lang_string="stringlang0\nstringlang1\n..laststring" */
  2105. void SetCombo(CWnd* _this,int id,char* lang_string) {
  2106.   CComboBox* combo = (CComboBox*) _this->GetDlgItem(id);
  2107.   CString st=lang_string;
  2108.   st.TrimLeft(); st.TrimRight();
  2109.   if (combo) {
  2110.     st+="\n";         /* end */
  2111.     combo->ResetContent();
  2112.     while(st.GetLength()) {
  2113.       int pos=st.Find('\n');
  2114.       CString item=st.Left(pos);
  2115.       st=st.Mid(pos+1);
  2116.       item.TrimLeft(); item.TrimRight();
  2117.       if (item.GetLength())
  2118.         combo->AddString(item);
  2119.     }
  2120.   }
  2121. }
  2122.  
  2123.  
  2124. // Ecriture profiles
  2125. CString profile_code(char* from) {
  2126.   int i;
  2127.   CString result;
  2128.   for(i = 0 ; from[i] != '\0' ; i++) {
  2129.     switch(from[i]) {
  2130.     case '%': 
  2131.       result += '%';
  2132.       result += '%';
  2133.       break;
  2134.     case '=': 
  2135.       result += '%';
  2136.       result += '3';
  2137.       result += 'd';
  2138.       break;
  2139.     case 13:
  2140.       result += '%';
  2141.       result += '0';
  2142.       result += 'd';
  2143.       break;
  2144.     case 10:
  2145.       result += '%';
  2146.       result += '0';
  2147.       result += 'a';
  2148.       break;
  2149.     case 9:
  2150.       result += '%';
  2151.       result += '0';
  2152.       result += '9';
  2153.       break;
  2154.     default:
  2155.       result += from[i];
  2156.       break;
  2157.     }
  2158.   }
  2159.   return result;
  2160. }
  2161. CString profile_decode(char* from) {
  2162.   int j;
  2163.   CString result;
  2164.   for(j = 0 ; from[j] != '\0' ; ) {  // oui oui
  2165.     if (from[j]=='%') {
  2166.       if (from[j + 1] == '%') {
  2167.         result += '%';
  2168.         j+=2;
  2169.       } else {
  2170.         if (strncmp(from+j+1,"0d", 2)==0)
  2171.           result += (char) 13;
  2172.         else if (strncmp(from+j+1,"0a", 2)==0)
  2173.           result += (char) 10;
  2174.         else if (strncmp(from+j+1,"09", 2)==0)
  2175.           result += (char) 9;
  2176.         else if (strncmp(from+j+1,"3d", 2)==0)
  2177.           result += '=';
  2178.         else
  2179.           result += ' ';
  2180.         j+=3;
  2181.       }
  2182.     } else
  2183.       result += from[j++];
  2184.   }
  2185.   return result;
  2186. }
  2187. //
  2188. // Ecriture/Lecture profiles
  2189. int MyWriteProfileInt(CString path,CString dummy,CString name,int value) {
  2190.   if (path.IsEmpty()) {
  2191.     CWinApp* pApp = AfxGetApp();
  2192.     pApp->WriteProfileInt(dummy,name,value);
  2193.   } else if (path=="<mem>") {       // buffer
  2194.     tmpm.setInt(name,value);
  2195.     return 0;
  2196.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2197.     if (tmpf) {
  2198.       return MyWriteProfileIntFile(tmpf,dummy,name,value);
  2199.     }
  2200.   } else {
  2201.     FILE* fp = fopen(path,"ab");
  2202.     if (fp) {
  2203.       int r=MyWriteProfileIntFile(fp,dummy,name,value);
  2204.       /*
  2205.       fprintf(fp,"%s=%d\x0d\x0a",name,value);
  2206.       */
  2207.       fclose(fp);
  2208.       return r;
  2209.     }
  2210.   }
  2211.   return 0;
  2212. }
  2213. int MyWriteProfileIntFile(FILE* fp,CString dummy,CString name,int value) {
  2214.   if (fp) {
  2215.     fprintf(fp,"%s=%d\x0d\x0a", name, value);
  2216.   }
  2217.   return 0;
  2218. }
  2219. int MyWriteProfileString(CString path,CString dummy,CString name,CString value) {
  2220.   if (path.IsEmpty()) {
  2221.     CWinApp* pApp = AfxGetApp();
  2222.     pApp->WriteProfileString(dummy, name, profile_code(value.GetBuffer(0)));
  2223.   } else if (path=="<mem>") {       // buffer
  2224.     tmpm.setString(name,value);
  2225.     return 0;
  2226.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2227.     if (tmpf) {
  2228.       return MyWriteProfileStringFile(tmpf,dummy,name,value);
  2229.     }
  2230.   } else {
  2231.     FILE* fp = fopen(path,"ab");
  2232.     if (fp) {
  2233.       int r=MyWriteProfileStringFile(fp,dummy,name,value);
  2234.       fclose(fp);
  2235.       return r;
  2236.     }
  2237.   }
  2238.   return 0;
  2239. }
  2240. int MyWriteProfileStringFile(FILE* fp,CString dummy,CString name,CString value) {
  2241.   if (fp) {
  2242.     fprintf(fp,"%s=%s\x0d\x0a", name, profile_code(value.GetBuffer(0)).GetBuffer(0));
  2243.   }
  2244.   return 0;
  2245. }
  2246. //
  2247. // lecture
  2248. int MyGetProfileInt(CString path,CString dummy,CString name,int value) {
  2249.   if (path.IsEmpty()) {
  2250.     CWinApp* pApp = AfxGetApp();
  2251.     return pApp->GetProfileInt(dummy, name, value);
  2252.   } else if (path=="<mem>") {       // buffer
  2253.     return tmpm.getInt(name,value);
  2254.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2255.     if (tmpf) {
  2256.       return MyGetProfileIntFile(tmpf,dummy,name,value);
  2257.     } else return value;
  2258.   } else {
  2259.     FILE* fp = fopen(path,"rb");
  2260.     if (fp) {
  2261.       int r=MyGetProfileIntFile(fp,dummy,name,value);
  2262.       fclose(fp);
  2263.       return r;
  2264.     } else return value;
  2265.   }
  2266. }
  2267. int MyGetProfileIntFile(FILE* fp,CString dummy,CString name,int value) {
  2268.   if (fp) {
  2269.     char srch[256];
  2270.     fseek(fp,0,SEEK_SET);
  2271.     sprintf(srch,"%s=",name);
  2272.     while(!feof(fp)) {
  2273.       char s[2048]; s[0]='\0';
  2274.       linput(fp,s,2000);
  2275.       if (strlen(s)==0)     // EOF
  2276.         return value;
  2277.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2278.         int val;
  2279.         if (sscanf(s+strlen(srch),"%d",&val) == 1)
  2280.           return val;
  2281.         else
  2282.           return value;
  2283.       }
  2284.     }
  2285.     return value;
  2286.   } else return value;
  2287. }
  2288. CString MyGetProfileString(CString path,CString dummy,CString name,CString value) {
  2289.   if (path.IsEmpty()) {
  2290.     CWinApp* pApp = AfxGetApp();
  2291.     return profile_decode(pApp->GetProfileString(dummy, name, profile_code(value.GetBuffer(0)).GetBuffer(0)).GetBuffer(0));
  2292.   } else if (path=="<mem>") {       // buffer
  2293.     return tmpm.getString(name,value);
  2294.   } else if (path=="<tmp>") {       // fichier temporaire commun
  2295.     if (tmpf) {
  2296.       return MyGetProfileStringFile(tmpf,dummy,name,value);
  2297.     } else return value;
  2298.   } else {
  2299.     FILE* fp = fopen(path,"rb");
  2300.     if (fp) {
  2301.       CString st=MyGetProfileStringFile(fp,dummy,name,value);
  2302.       fclose(fp);
  2303.       return st;
  2304.     } else return value;
  2305.   }
  2306. }
  2307. CString MyGetProfileStringFile(FILE* fp,CString dummy,CString name,CString value) {
  2308.   if (fp) {
  2309.     char srch[256];
  2310.     fseek(fp,0,SEEK_SET);
  2311.     sprintf(srch,"%s",name);
  2312.     strcatbuff(srch,"=");
  2313.     while(!feof(fp)) {
  2314.       char s[32768]; s[0]='\0';
  2315.       linput(fp,s,32000);
  2316.       if (strlen(s)==0)     // EOF
  2317.         return value;
  2318.       if (strncmp(s,srch,strlen(srch)) == 0) {    // ligne reconnue
  2319.         return profile_decode(s+strlen(srch));
  2320.       }
  2321.     }
  2322.     return value;
  2323.   } else return value;
  2324. }
  2325.  
  2326. //
  2327. // Get_profile et Write_profile eux mΩmes
  2328. //
  2329. // path="" -> Θcrire dans la base (default)
  2330. // path="<tmp>" -> Θcrire dans le fichier tempo commun
  2331. // path="<mem>" -> Θcrire dans le buffer tempo commun
  2332. // path="<null>" -> lire default (illΘgal en Θcriture)
  2333. void Write_profile(CString path,int load_path) {
  2334.   CWaitCursor wait;
  2335.   CString strSection       = "OptionsValues";
  2336.   CString st;
  2337.   int n;
  2338.   
  2339.   // Fichier tempo ou fichier?
  2340.   if (path=="<tmp>") {     // fichier temporaire
  2341.     if (tmpf)
  2342.       fclose(tmpf);
  2343.     tmpf=tmpfile();
  2344.     if (!tmpf)
  2345.       return;
  2346.   } else if (path=="<mem>") {     // buffer temporaire
  2347.     tmpm.deleteAll();
  2348.   } else if (!(path.IsEmpty())) {
  2349.     FILE *fp=fopen(path,"wb");
  2350.     if (fp) 
  2351.       fclose(fp);
  2352.   }
  2353.   
  2354.   //if (dialog3.m_hWnd == NULL) {    // pas initialisΘ
  2355.   if (maintab->m_hWnd == NULL) {    // pas initialisΘ
  2356.     // checkboxes
  2357.     MyWriteProfileInt(path,strSection, "Near",maintab->m_option1.m_link);
  2358.     MyWriteProfileInt(path,strSection, "Test",maintab->m_option1.m_testall);
  2359.     MyWriteProfileInt(path,strSection, "ParseAll",maintab->m_option1.m_parseall);
  2360.     MyWriteProfileInt(path,strSection, "HTMLFirst",maintab->m_option1.m_htmlfirst);
  2361.     MyWriteProfileInt(path,strSection, "Cache",maintab->m_option3.m_cache);
  2362.     MyWriteProfileInt(path,strSection, "NoRecatch",maintab->m_option9.m_norecatch);
  2363.     MyWriteProfileInt(path,strSection, "Dos",
  2364.       ((maintab->m_option2.m_dos)?1:0)
  2365.       +
  2366.       (((maintab->m_option2.m_iso9660)?1:0)<<1)
  2367.       );
  2368.     MyWriteProfileInt(path,strSection, "Index",maintab->m_option9.m_index);
  2369.     MyWriteProfileInt(path,strSection, "WordIndex",maintab->m_option9.m_index2);
  2370.     MyWriteProfileInt(path,strSection, "Log",maintab->m_option9.m_logf);
  2371.     MyWriteProfileInt(path,strSection, "RemoveTimeout",maintab->m_option4.m_remt);
  2372.     MyWriteProfileInt(path,strSection, "RemoveRateout",maintab->m_option4.m_rems);
  2373.     MyWriteProfileInt(path,strSection, "KeepAlive",maintab->m_option4.m_ka);
  2374.     MyWriteProfileInt(path,strSection, "FollowRobotsTxt",maintab->m_option8.m_robots);
  2375.     MyWriteProfileInt(path,strSection, "NoErrorPages",maintab->m_option2.m_errpage);
  2376.     MyWriteProfileInt(path,strSection, "NoExternalPages",maintab->m_option2.m_external);
  2377.     MyWriteProfileInt(path,strSection, "NoPwdInPages",maintab->m_option2.m_hidepwd);
  2378.     MyWriteProfileInt(path,strSection, "NoQueryStrings",maintab->m_option2.m_hidequery);
  2379.     MyWriteProfileInt(path,strSection, "NoPurgeOldFiles",maintab->m_option2.m_nopurge);
  2380.     MyWriteProfileInt(path,strSection, "Cookies",maintab->m_option8.m_cookies);
  2381.     MyWriteProfileInt(path,strSection, "CheckType",maintab->m_option8.m_checktype);
  2382.     MyWriteProfileInt(path,strSection, "ParseJava",maintab->m_option8.m_parsejava);
  2383.     MyWriteProfileInt(path,strSection, "HTTP10",maintab->m_option8.m_http10);
  2384.     MyWriteProfileInt(path,strSection, "TolerantRequests",maintab->m_option8.m_toler);
  2385.     MyWriteProfileInt(path,strSection, "UpdateHack",maintab->m_option8.m_updhack);
  2386.     MyWriteProfileInt(path,strSection, "URLHack",maintab->m_option8.m_urlhack);
  2387.     MyWriteProfileInt(path,strSection, "StoreAllInCache",maintab->m_option9.m_Cache2);
  2388.     MyWriteProfileInt(path,strSection, "LogType",maintab->m_option9.m_logtype);
  2389.     MyWriteProfileInt(path,strSection, "UseHTTPProxyForFTP",maintab->m_option10.m_ftpprox);
  2390.     
  2391.     // menus
  2392.     MyWriteProfileInt(path,strSection, "Build",maintab->m_option2.m_build);
  2393.     MyWriteProfileInt(path,strSection, "PrimaryScan",maintab->m_option3.m_filter);
  2394.     MyWriteProfileInt(path,strSection, "Travel",maintab->m_option3.m_travel);
  2395.     MyWriteProfileInt(path,strSection, "GlobalTravel",maintab->m_option3.m_travel2);
  2396.     MyWriteProfileInt(path,strSection, "RewriteLinks",maintab->m_option3.m_travel3);
  2397.     MyWriteProfileString(path,strSection, "BuildString",maintab->m_option2.Bopt.m_BuildString);
  2398.     
  2399.     // champs
  2400.     MyWriteProfileString(path,strSection, "Category", this_CSplitterFrame->GetCurrentCategory());
  2401.  
  2402.     MyWriteProfileString(path,strSection, "MaxHtml",maintab->m_option5.m_maxhtml);
  2403.     MyWriteProfileString(path,strSection, "MaxOther",maintab->m_option5.m_othermax);
  2404.     MyWriteProfileString(path,strSection, "MaxAll",maintab->m_option5.m_sizemax);
  2405.     MyWriteProfileString(path,strSection, "MaxWait",maintab->m_option5.m_pausebytes);
  2406.     MyWriteProfileString(path,strSection, "Sockets",maintab->m_option4.m_connexion);
  2407.     MyWriteProfileString(path,strSection, "Retry",maintab->m_option4.m_retry);
  2408.     MyWriteProfileString(path,strSection, "MaxTime",maintab->m_option5.m_maxtime);
  2409.     MyWriteProfileString(path,strSection, "TimeOut",maintab->m_option4.m_timeout);
  2410.     MyWriteProfileString(path,strSection, "RateOut",maintab->m_option4.m_rate);
  2411.     MyWriteProfileString(path,strSection, "UserID",maintab->m_option6.m_user);
  2412.     MyWriteProfileString(path,strSection, "Footer",maintab->m_option6.m_footer);
  2413.     MyWriteProfileString(path,strSection, "MaxRate",maintab->m_option5.m_maxrate);
  2414.     MyWriteProfileString(path,strSection, "WildCardFilters",maintab->m_option7.m_url2);
  2415.     MyWriteProfileString(path,strSection, "Proxy",maintab->m_option10.m_proxy);
  2416.     MyWriteProfileString(path,strSection, "Port",maintab->m_option10.m_port);
  2417.     MyWriteProfileString(path,strSection, "Depth",maintab->m_option5.m_depth);
  2418.     MyWriteProfileString(path,strSection, "ExtDepth",maintab->m_option5.m_depth2);
  2419.     MyWriteProfileString(path,strSection, "MaxConn",maintab->m_option5.m_maxconn);    
  2420.     MyWriteProfileString(path,strSection, "MaxLinks",maintab->m_option5.m_maxlinks);    
  2421.     
  2422.     // 11
  2423.     MyWriteProfileString(path,strSection, "MIMEDefsExt1",maintab->m_option11.m_ext1);    
  2424.     MyWriteProfileString(path,strSection, "MIMEDefsExt2",maintab->m_option11.m_ext2);    
  2425.     MyWriteProfileString(path,strSection, "MIMEDefsExt3",maintab->m_option11.m_ext3);    
  2426.     MyWriteProfileString(path,strSection, "MIMEDefsExt4",maintab->m_option11.m_ext4);    
  2427.     MyWriteProfileString(path,strSection, "MIMEDefsExt5",maintab->m_option11.m_ext5);    
  2428.     MyWriteProfileString(path,strSection, "MIMEDefsExt6",maintab->m_option11.m_ext6);    
  2429.     MyWriteProfileString(path,strSection, "MIMEDefsExt7",maintab->m_option11.m_ext7);    
  2430.     MyWriteProfileString(path,strSection, "MIMEDefsExt8",maintab->m_option11.m_ext8);    
  2431.     MyWriteProfileString(path,strSection, "MIMEDefsMime1",maintab->m_option11.m_mime1);    
  2432.     MyWriteProfileString(path,strSection, "MIMEDefsMime2",maintab->m_option11.m_mime2);    
  2433.     MyWriteProfileString(path,strSection, "MIMEDefsMime3",maintab->m_option11.m_mime3);    
  2434.     MyWriteProfileString(path,strSection, "MIMEDefsMime4",maintab->m_option11.m_mime4);    
  2435.     MyWriteProfileString(path,strSection, "MIMEDefsMime5",maintab->m_option11.m_mime5);    
  2436.     MyWriteProfileString(path,strSection, "MIMEDefsMime6",maintab->m_option11.m_mime6);    
  2437.     MyWriteProfileString(path,strSection, "MIMEDefsMime7",maintab->m_option11.m_mime7);    
  2438.     MyWriteProfileString(path,strSection, "MIMEDefsMime8",maintab->m_option11.m_mime8);
  2439.   } else {
  2440.     st = this_CSplitterFrame->GetCurrentCategory(); MyWriteProfileString(path,strSection,"Category",st);
  2441.  
  2442.     // checkboxes
  2443.     // 1
  2444.     n=maintab->m_option1.IsDlgButtonChecked(IDC_link);
  2445.     MyWriteProfileInt(path,strSection,"Near", n);
  2446.     n=maintab->m_option1.IsDlgButtonChecked(IDC_testall);
  2447.     MyWriteProfileInt(path,strSection,"Test", n);
  2448.     n=maintab->m_option1.IsDlgButtonChecked(IDC_parseall);
  2449.     MyWriteProfileInt(path,strSection,"ParseAll", n);
  2450.     n=maintab->m_option1.IsDlgButtonChecked(IDC_htmlfirst);
  2451.     MyWriteProfileInt(path,strSection,"HTMLFirst", n);
  2452.     // 2
  2453.     n=maintab->m_option3.IsDlgButtonChecked(IDC_Cache);
  2454.     MyWriteProfileInt(path,strSection,"Cache", n);
  2455.     n=maintab->m_option2.IsDlgButtonChecked(IDC_norecatch);
  2456.     MyWriteProfileInt(path,strSection,"NoRecatch", n);
  2457.     n = ((maintab->m_option2.IsDlgButtonChecked(IDC_dos))?1:0)
  2458.       + ((maintab->m_option2.IsDlgButtonChecked(IDC_iso9660)?1:0)<<1);
  2459.     MyWriteProfileInt(path,strSection,"Dos", n);
  2460.     n=maintab->m_option2.IsDlgButtonChecked(IDC_index);
  2461.     MyWriteProfileInt(path,strSection,"Index", n);
  2462.     n=maintab->m_option2.IsDlgButtonChecked(IDC_index2);
  2463.     MyWriteProfileInt(path,strSection,"WordIndex", n);
  2464.     n=maintab->m_option2.IsDlgButtonChecked(IDC_logf);
  2465.     MyWriteProfileInt(path,strSection,"Log", n);
  2466.     n=maintab->m_option2.IsDlgButtonChecked(IDC_errpage);
  2467.     MyWriteProfileInt(path,strSection,"NoErrorPages", n);
  2468.     n=maintab->m_option2.IsDlgButtonChecked(IDC_hidepwd);
  2469.     MyWriteProfileInt(path,strSection,"NoPwdInPages", n);
  2470.     n=maintab->m_option2.IsDlgButtonChecked(IDC_hidequery);
  2471.     MyWriteProfileInt(path,strSection,"NoQueryStrings", n);
  2472.     n=maintab->m_option2.IsDlgButtonChecked(IDC_external);
  2473.     MyWriteProfileInt(path,strSection,"NoExternalPages", n);
  2474.     n=maintab->m_option2.IsDlgButtonChecked(IDC_nopurge);
  2475.     MyWriteProfileInt(path,strSection,"NoPurgeOldFiles", n);
  2476.     if ((n=maintab->m_option2.m_ctl_build.GetCurSel()) != CB_ERR)
  2477.       MyWriteProfileInt(path,strSection, "Build", n);
  2478.     st = maintab->m_option2.Bopt.m_BuildString;
  2479.     if (st.GetLength()>0)
  2480.       MyWriteProfileString(path,strSection, "BuildString",st);
  2481.     // 3
  2482.     // menus
  2483.     if ((n=maintab->m_option3.m_ctl_filter.GetCurSel()) != CB_ERR)
  2484.       MyWriteProfileInt(path,strSection, "PrimaryScan", n);
  2485.     if ((n=maintab->m_option3.m_ctl_travel.GetCurSel()) != CB_ERR)
  2486.       MyWriteProfileInt(path,strSection, "Travel", n);
  2487.     if ((n=maintab->m_option3.m_ctl_travel2.GetCurSel()) != CB_ERR)
  2488.       MyWriteProfileInt(path,strSection, "GlobalTravel", n);
  2489.     if ((n=maintab->m_option3.m_ctl_travel3.GetCurSel()) != CB_ERR)
  2490.       MyWriteProfileInt(path,strSection, "RewriteLinks", n);
  2491.     //
  2492.     maintab->m_option8.GetDlgItemText(IDC_robots,st);
  2493.     MyWriteProfileString(path,strSection, "FollowRobotsTxt", st);
  2494.     // 4
  2495.     maintab->m_option4.GetDlgItemText(IDC_connexion,st);
  2496.     MyWriteProfileString(path,strSection, "Sockets", st);
  2497.     maintab->m_option4.GetDlgItemText(IDC_timeout,st);
  2498.     MyWriteProfileString(path,strSection, "TimeOut", st);
  2499.     n=maintab->m_option4.IsDlgButtonChecked(IDC_remt);
  2500.     MyWriteProfileInt(path,strSection,"RemoveTimeout", n);
  2501.     maintab->m_option4.GetDlgItemText(IDC_retry,st);
  2502.     MyWriteProfileString(path,strSection, "Retry", st);
  2503.     maintab->m_option4.GetDlgItemText(IDC_rate,st);
  2504.     MyWriteProfileString(path,strSection, "RateOut", st);
  2505.     n=maintab->m_option4.IsDlgButtonChecked(IDC_rems);
  2506.     MyWriteProfileInt(path,strSection,"RemoveRateout", n);
  2507.     n=maintab->m_option4.IsDlgButtonChecked(IDC_ka);
  2508.     MyWriteProfileInt(path,strSection,"KeepAlive", n);
  2509.     // 5
  2510.     maintab->m_option5.GetDlgItemText(IDC_maxhtml,st);
  2511.     MyWriteProfileString(path,strSection, "MaxHtml", st);
  2512.     maintab->m_option5.GetDlgItemText(IDC_othermax,st);
  2513.     MyWriteProfileString(path,strSection, "MaxOther", st);
  2514.     maintab->m_option5.GetDlgItemText(IDC_sizemax,st);
  2515.     MyWriteProfileString(path,strSection, "MaxAll", st);
  2516.     maintab->m_option5.GetDlgItemText(IDC_pausebytes,st);
  2517.     MyWriteProfileString(path,strSection, "MaxWait", st);
  2518.     maintab->m_option5.GetDlgItemText(IDC_maxtime,st);
  2519.     MyWriteProfileString(path,strSection, "MaxTime", st);
  2520.     maintab->m_option5.GetDlgItemText(IDC_maxrate,st);
  2521.     MyWriteProfileString(path,strSection, "MaxRate", st);
  2522.     maintab->m_option5.GetDlgItemText(IDC_depth,st);
  2523.     MyWriteProfileString(path,strSection,"Depth",st);
  2524.     maintab->m_option5.GetDlgItemText(IDC_depth2,st);
  2525.     MyWriteProfileString(path,strSection,"ExtDepth",st);
  2526.     maintab->m_option5.GetDlgItemText(IDC_maxconn,st);
  2527.     MyWriteProfileString(path,strSection, "MaxConn", st);
  2528.     maintab->m_option5.GetDlgItemText(IDC_maxlinks,st);
  2529.     MyWriteProfileString(path,strSection, "MaxLinks", st);
  2530.     // 6
  2531.     maintab->m_option6.GetDlgItemText(IDC_user,st);
  2532.     MyWriteProfileString(path,strSection, "UserID", st);
  2533.     maintab->m_option6.GetDlgItemText(IDC_footer,st);
  2534.     MyWriteProfileString(path,strSection, "Footer", st);
  2535.     // 7
  2536.     maintab->m_option7.GetDlgItemText(IDC_URL2,st);
  2537.     MyWriteProfileString(path,strSection, "WildCardFilters", st);
  2538.     // 8
  2539.     maintab->m_option8.GetDlgItemText(IDC_cookies,st);
  2540.     MyWriteProfileString(path,strSection, "Cookies", st);
  2541.     maintab->m_option8.GetDlgItemText(IDC_checktype,st);
  2542.     MyWriteProfileString(path,strSection, "CheckType", st);
  2543.     n=maintab->m_option8.IsDlgButtonChecked(IDC_parsejava);
  2544.     MyWriteProfileInt(path,strSection, "ParseJava", n);
  2545.     n=maintab->m_option8.IsDlgButtonChecked(IDC_http10);
  2546.     MyWriteProfileInt(path,strSection, "HTTP10", n);
  2547.     n=maintab->m_option8.IsDlgButtonChecked(IDC_toler);
  2548.     MyWriteProfileInt(path,strSection, "TolerantRequests", n);
  2549.     n=maintab->m_option8.IsDlgButtonChecked(IDC_updhack);
  2550.     MyWriteProfileInt(path,strSection, "UpdateHack", n);
  2551.     n=maintab->m_option8.IsDlgButtonChecked(IDC_urlhack);
  2552.     MyWriteProfileInt(path,strSection, "URLHack", n);
  2553.     // 9
  2554.     maintab->m_option9.GetDlgItemText(IDC_Cache2,st);
  2555.     MyWriteProfileString(path,strSection, "StoreAllInCache", st);
  2556.     maintab->m_option9.GetDlgItemText(IDC_logtype,st);
  2557.     MyWriteProfileString(path,strSection, "LogType", st);
  2558.     // 10
  2559.     maintab->m_option10.GetDlgItemText(IDC_prox,st);
  2560.     MyWriteProfileString(path,strSection,"Proxy",st);
  2561.     maintab->m_option10.GetDlgItemText(IDC_proxport,st);
  2562.     MyWriteProfileString(path,strSection,"Port",st);
  2563.     n=maintab->m_option10.IsDlgButtonChecked(IDC_ftpprox);
  2564.     MyWriteProfileInt(path,strSection,"UseHTTPProxyForFTP", n);
  2565.     
  2566.     // 11
  2567.     maintab->m_option11.GetDlgItemText(IDC_ext1,st); MyWriteProfileString(path,strSection,"MIMEDefsExt1",st);
  2568.     maintab->m_option11.GetDlgItemText(IDC_ext2,st); MyWriteProfileString(path,strSection,"MIMEDefsExt2",st);
  2569.     maintab->m_option11.GetDlgItemText(IDC_ext3,st); MyWriteProfileString(path,strSection,"MIMEDefsExt3",st);
  2570.     maintab->m_option11.GetDlgItemText(IDC_ext4,st); MyWriteProfileString(path,strSection,"MIMEDefsExt4",st);
  2571.     maintab->m_option11.GetDlgItemText(IDC_ext5,st); MyWriteProfileString(path,strSection,"MIMEDefsExt5",st);
  2572.     maintab->m_option11.GetDlgItemText(IDC_ext6,st); MyWriteProfileString(path,strSection,"MIMEDefsExt6",st);
  2573.     maintab->m_option11.GetDlgItemText(IDC_ext7,st); MyWriteProfileString(path,strSection,"MIMEDefsExt7",st);
  2574.     maintab->m_option11.GetDlgItemText(IDC_ext8,st); MyWriteProfileString(path,strSection,"MIMEDefsExt8",st);
  2575.     maintab->m_option11.GetDlgItemText(IDC_mime1,st); MyWriteProfileString(path,strSection,"MIMEDefsMime1",st);
  2576.     maintab->m_option11.GetDlgItemText(IDC_mime2,st); MyWriteProfileString(path,strSection,"MIMEDefsMime2",st);
  2577.     maintab->m_option11.GetDlgItemText(IDC_mime3,st); MyWriteProfileString(path,strSection,"MIMEDefsMime3",st);
  2578.     maintab->m_option11.GetDlgItemText(IDC_mime4,st); MyWriteProfileString(path,strSection,"MIMEDefsMime4",st);
  2579.     maintab->m_option11.GetDlgItemText(IDC_mime5,st); MyWriteProfileString(path,strSection,"MIMEDefsMime5",st);
  2580.     maintab->m_option11.GetDlgItemText(IDC_mime6,st); MyWriteProfileString(path,strSection,"MIMEDefsMime6",st);
  2581.     maintab->m_option11.GetDlgItemText(IDC_mime7,st); MyWriteProfileString(path,strSection,"MIMEDefsMime7",st);
  2582.     maintab->m_option11.GetDlgItemText(IDC_mime8,st); MyWriteProfileString(path,strSection,"MIMEDefsMime8",st);
  2583.   }
  2584.   // liens, jokers etc. si mirror merge
  2585.   if (!(path.IsEmpty())) {
  2586.     if (dialog1->m_hWnd == NULL) {    // pas initialisΘ
  2587.       //MyWriteProfileString(path,strSection,"CurrentDepth",dialog1->m_depth);
  2588.       MyWriteProfileString(path,strSection,"CurrentUrl",dialog1->m_urls);
  2589.       if (dialog1->m_todo >= 0)
  2590.         MyWriteProfileInt(path, strSection,"CurrentAction", dialog1->m_todo);
  2591.       //
  2592.       MyWriteProfileString(path,strSection,"CurrentURLList",dialog1->m_filelist);
  2593.       
  2594.       //if (load_path) {
  2595.       //MyWriteProfileString(path,strSection,"CurrentPath1",dialog0->GetPath());
  2596.       //MyWriteProfileString(path,strSection,"CurrentPath2",dialog0->GetPath());
  2597.       //}
  2598.     } else {
  2599.       //dialog1->GetDlgItemText(IDC_depth,st);
  2600.       //MyWriteProfileString(path,strSection,"CurrentDepth",st);
  2601.       dialog1->GetDlgItemText(IDC_URL,st);
  2602.       MyWriteProfileString(path,strSection,"CurrentUrl",st);
  2603.       if ((n=dialog1->m_ctl_todo.GetCurSel()) != CB_ERR)
  2604.         MyWriteProfileInt(path,strSection, "CurrentAction", n);
  2605.       //
  2606.       dialog1->GetDlgItemText(IDC_filelist,st);
  2607.       MyWriteProfileString(path,strSection,"CurrentURLList",st);
  2608.       //
  2609.       //if (load_path) {
  2610.       //dialog1->GetDlgItemText(IDC_pathlog,st);
  2611.       //MyWriteProfileString(path,strSection,"CurrentPath1",st);
  2612.       //dialog1->GetDlgItemText(IDC_pthmir,st);
  2613.       //MyWriteProfileString(path,strSection,"CurrentPath2",st);
  2614.       //}
  2615.     }
  2616.   }
  2617. }
  2618. // path="" -> lire dans la base (default)
  2619. //if not exist: do not load anything but patches projname&co
  2620. void Read_profile(CString path,int load_path) {
  2621.   CWaitCursor wait;
  2622.   CString strSection       = "OptionsValues";
  2623.   CString st;
  2624.   
  2625.   // VΘrification <tmp>
  2626.   if (path=="<tmp>") {     // fichier temporaire
  2627.     if (!tmpf)
  2628.       return;
  2629.     else
  2630.       fflush(tmpf);
  2631.   } else if (path=="<null>") {     // options par dΘfaut
  2632.     path="<mem>";
  2633.     tmpm.deleteAll();              // effacer
  2634.   } else {
  2635.     int pos=path.ReverseFind('\\');
  2636.     if (pos>=0) {
  2637.       CString dir=path.Left(pos);           // enlever winprofile.ini
  2638.       pos=dir.ReverseFind('\\');
  2639.       if (pos>=0) {
  2640.         dir=dir.Left(pos);                  // enlever hts-cache
  2641.         pos=dir.ReverseFind('\\');
  2642.         if (pos>=0) {
  2643.           dialog0->m_projname=dir.Mid(pos+1);
  2644.           dialog0->m_projpath=dir.Left(pos);
  2645.           /*
  2646.           if (this_CWizTab)
  2647.           this_CWizTab->SetActivePage(2);     // page 3
  2648.           */
  2649.         }
  2650.       }
  2651.     }
  2652.   }
  2653.   
  2654.   // checkboxes
  2655.   maintab->m_option1.m_link      = MyGetProfileInt(path,strSection, "Near",0);
  2656.   maintab->m_option1.m_testall   = MyGetProfileInt(path,strSection, "Test",0);
  2657.   maintab->m_option1.m_parseall  = MyGetProfileInt(path,strSection, "ParseAll",1);
  2658.   maintab->m_option1.m_htmlfirst = MyGetProfileInt(path,strSection, "HTMLFirst",0);
  2659.   maintab->m_option3.m_cache     = MyGetProfileInt(path,strSection, "Cache",1);
  2660.   maintab->m_option9.m_norecatch = MyGetProfileInt(path,strSection, "NoRecatch",0);
  2661.   maintab->m_option2.m_dos       = (MyGetProfileInt(path,strSection, "Dos",0) & 1);
  2662.   maintab->m_option2.m_iso9660   = ((MyGetProfileInt(path,strSection, "Dos",0) & 2)>>1);
  2663.   maintab->m_option9.m_index     = MyGetProfileInt(path,strSection, "Index",1);
  2664.   maintab->m_option9.m_index2    = MyGetProfileInt(path,strSection, "WordIndex",0);
  2665.   maintab->m_option9.m_logf      = MyGetProfileInt(path,strSection, "Log",1);
  2666.   maintab->m_option4.m_remt      = MyGetProfileInt(path,strSection, "RemoveTimeout",0);
  2667.   maintab->m_option4.m_rems      = MyGetProfileInt(path,strSection, "RemoveRateout",0);
  2668.   maintab->m_option4.m_ka        = MyGetProfileInt(path,strSection, "KeepAlive",1);
  2669.   maintab->m_option8.m_robots    = MyGetProfileInt(path,strSection, "FollowRobotsTxt",2);
  2670.   maintab->m_option2.m_errpage   = MyGetProfileInt(path,strSection, "NoErrorPages",0);
  2671.   maintab->m_option2.m_external  = MyGetProfileInt(path,strSection, "NoExternalPages",0);
  2672.   maintab->m_option2.m_hidepwd   = MyGetProfileInt(path,strSection, "NoPwdInPages",0);
  2673.   maintab->m_option2.m_hidequery = MyGetProfileInt(path,strSection, "NoQueryStrings",0);
  2674.   maintab->m_option2.m_nopurge   = MyGetProfileInt(path,strSection, "NoPurgeOldFiles",0);
  2675.   maintab->m_option8.m_cookies    = MyGetProfileInt(path,strSection, "Cookies",1);
  2676.   maintab->m_option8.m_checktype  = MyGetProfileInt(path,strSection, "CheckType",1);
  2677.   maintab->m_option8.m_parsejava  = MyGetProfileInt(path,strSection, "ParseJava",1);
  2678.   maintab->m_option8.m_toler      = MyGetProfileInt(path,strSection, "TolerantRequests",0);
  2679.   maintab->m_option8.m_updhack    = MyGetProfileInt(path,strSection, "UpdateHack",1);
  2680.   maintab->m_option8.m_urlhack    = MyGetProfileInt(path,strSection, "URLHack",1);
  2681.   maintab->m_option8.m_http10     = MyGetProfileInt(path,strSection, "HTTP10",0);
  2682.   maintab->m_option9.m_Cache2     = MyGetProfileInt(path,strSection, "StoreAllInCache",0);
  2683.   maintab->m_option9.m_logtype    = MyGetProfileInt(path,strSection, "LogType",0);
  2684.   
  2685.   // menus
  2686.   maintab->m_option2.m_build   = MyGetProfileInt(path,strSection, "Build",0);
  2687.   maintab->m_option3.m_filter  = MyGetProfileInt(path,strSection, "PrimaryScan",3);
  2688.   maintab->m_option3.m_travel  = MyGetProfileInt(path,strSection, "Travel",1);
  2689.   maintab->m_option3.m_travel2 = MyGetProfileInt(path,strSection, "GlobalTravel",0);
  2690.   maintab->m_option3.m_travel3 = MyGetProfileInt(path,strSection, "RewriteLinks",0);
  2691.   maintab->m_option2.Bopt.m_BuildString = MyGetProfileString(path,strSection, "BuildString","%h%p/%n%q.%t");
  2692.   
  2693.   // champs
  2694.   dialog0->m_projcateg =          MyGetProfileString(path,strSection, "Category");
  2695.  
  2696.   maintab->m_option5.m_maxhtml =  MyGetProfileString(path,strSection, "MaxHtml");
  2697.   maintab->m_option5.m_othermax=  MyGetProfileString(path,strSection, "MaxOther");
  2698.   maintab->m_option5.m_sizemax =  MyGetProfileString(path,strSection, "MaxAll");
  2699.   maintab->m_option5.m_pausebytes=MyGetProfileString(path,strSection, "MaxWait");  
  2700.   maintab->m_option4.m_connexion= MyGetProfileString(path,strSection, "Sockets");
  2701.   maintab->m_option4.m_retry   =  MyGetProfileString(path,strSection, "Retry");
  2702.   maintab->m_option5.m_maxtime =  MyGetProfileString(path,strSection, "MaxTime");
  2703.   maintab->m_option4.m_timeout =  MyGetProfileString(path,strSection, "TimeOut");
  2704.   maintab->m_option4.m_rate    =  MyGetProfileString(path,strSection, "RateOut");
  2705.   maintab->m_option6.m_user    =  MyGetProfileString(path,strSection, "UserID","Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)");
  2706.   maintab->m_option6.m_footer  =  MyGetProfileString(path,strSection, "Footer",HTS_DEFAULT_FOOTER);
  2707.   maintab->m_option5.m_maxrate =  MyGetProfileString(path,strSection, "MaxRate", "25000");
  2708.   maintab->m_option5.m_maxconn =  MyGetProfileString(path,strSection, "MaxConn");
  2709.   maintab->m_option5.m_maxlinks = MyGetProfileString(path,strSection, "MaxLinks");
  2710.   
  2711.   // 7
  2712.   maintab->m_option7.m_url2 = MyGetProfileString(path,strSection, "WildCardFilters","+*.png +*.gif +*.jpg +*.css +*.js -ad.doubleclick.net/*");
  2713.   
  2714.   // 10
  2715.   maintab->m_option10.m_proxy   = MyGetProfileString(path,strSection, "Proxy");
  2716.   maintab->m_option10.m_port    = MyGetProfileString(path,strSection, "Port");
  2717.   maintab->m_option10.m_ftpprox = MyGetProfileInt(path,strSection, "UseHTTPProxyForFTP",1);
  2718.   //
  2719.   maintab->m_option5.m_depth    = MyGetProfileString(path,strSection, "Depth");
  2720.   maintab->m_option5.m_depth2   = MyGetProfileString(path,strSection, "ExtDepth");
  2721.   
  2722.   // 11
  2723.   maintab->m_option11.m_ext1   = MyGetProfileString(path,strSection, "MIMEDefsExt1", "php3,php,php2,asp,jsp,pl,cfm,nsf");
  2724.   maintab->m_option11.m_ext2   = MyGetProfileString(path,strSection, "MIMEDefsExt2");
  2725.   maintab->m_option11.m_ext3   = MyGetProfileString(path,strSection, "MIMEDefsExt3");
  2726.   maintab->m_option11.m_ext4   = MyGetProfileString(path,strSection, "MIMEDefsExt4");
  2727.   maintab->m_option11.m_ext5   = MyGetProfileString(path,strSection, "MIMEDefsExt5");
  2728.   maintab->m_option11.m_ext6   = MyGetProfileString(path,strSection, "MIMEDefsExt6");
  2729.   maintab->m_option11.m_ext7   = MyGetProfileString(path,strSection, "MIMEDefsExt7");
  2730.   maintab->m_option11.m_ext8   = MyGetProfileString(path,strSection, "MIMEDefsExt8");
  2731.   maintab->m_option11.m_mime1   = MyGetProfileString(path,strSection, "MIMEDefsMime1", "text/html");
  2732.   maintab->m_option11.m_mime2   = MyGetProfileString(path,strSection, "MIMEDefsMime2");
  2733.   maintab->m_option11.m_mime3   = MyGetProfileString(path,strSection, "MIMEDefsMime3");
  2734.   maintab->m_option11.m_mime4   = MyGetProfileString(path,strSection, "MIMEDefsMime4");
  2735.   maintab->m_option11.m_mime5   = MyGetProfileString(path,strSection, "MIMEDefsMime5");
  2736.   maintab->m_option11.m_mime6   = MyGetProfileString(path,strSection, "MIMEDefsMime6");
  2737.   maintab->m_option11.m_mime7   = MyGetProfileString(path,strSection, "MIMEDefsMime7");
  2738.   maintab->m_option11.m_mime8   = MyGetProfileString(path,strSection, "MIMEDefsMime8");
  2739.   
  2740.   
  2741.   //st = MyGetProfileString(path,strSection,"WildCardFilters");
  2742.   //ShellOptions->buff_filtres = st;
  2743.   
  2744.   // liens, jokers etc. si mirror merge
  2745.   if (!(path.IsEmpty())) {
  2746.     if (dialog1->m_hWnd == NULL) {    // pas initialisΘ
  2747.       //dialog1->m_depth  = MyGetProfileString(path,strSection,"CurrentDepth");
  2748.       dialog1->m_urls     = MyGetProfileString(path,strSection,"CurrentUrl");
  2749.       dialog1->m_todo     = MyGetProfileInt(path,strSection,"CurrentAction",0);
  2750.       dialog1->m_filelist = MyGetProfileString(path,strSection,"CurrentURLList");
  2751.       /*
  2752.       if (load_path) {
  2753.       CString st;
  2754.       st = MyGetProfileString(path,strSection,"CurrentPath1");
  2755.       if (st != "")
  2756.       dialog1->m_pathlog = st;
  2757.       st = MyGetProfileString(path,strSection,"CurrentPath2");
  2758.       if (st != "")
  2759.       dialog1->m_pathmir = st;
  2760.       }
  2761.       */
  2762.     } else {
  2763.       //st = MyGetProfileString(path,strSection,"CurrentDepth");
  2764.       //dialog1->SetDlgItemText(IDC_depth,st);
  2765.       st = MyGetProfileString(path,strSection,"CurrentUrl");
  2766.       SetDlgItemTextCP(dialog1, IDC_URL,st);
  2767.       int n = MyGetProfileInt(path,strSection,"CurrentAction",0);
  2768.       dialog1->m_ctl_todo.SetCurSel(n);
  2769.       st = MyGetProfileString(path,strSection,"CurrentURLList");
  2770.       SetDlgItemTextCP(dialog1, IDC_filelist,st);
  2771.       /*
  2772.       if (load_path) {
  2773.       st = MyGetProfileString(path,strSection,"CurrentPath1");
  2774.       if (st != "")
  2775.       dialog1->SetDlgItemText(IDC_pathlog,st);
  2776.       st = MyGetProfileString(path,strSection,"CurrentPath2");
  2777.       if (st != "")
  2778.       dialog1->SetDlgItemText(IDC_pthmir,st);
  2779.       }
  2780.       */
  2781.       dialog1->Refresh();
  2782.     }
  2783.   }
  2784.   
  2785. }
  2786.  
  2787. // Initialisation du RAS
  2788. void InitRAS() {
  2789. #if USE_RAS
  2790.   if (!LibRas) {
  2791.     LibRas=new CDynamicRAS();
  2792.     if (LibRas->IsRASLoaded()) 
  2793.       LibRasUse=1;
  2794.     else
  2795.       LibRasUse=0;
  2796.   }
  2797. #endif
  2798. }
  2799.  
  2800. // Reconstruire index gΘnΘral!
  2801. void Build_TopIndex(BOOL check_empty) {
  2802.   CWaitCursor wait;
  2803.  
  2804.   //if (toptemplate_header && toptemplate_body && toptemplate_footer) {
  2805.   {
  2806.     char path[HTS_URLMAXSIZE*2];
  2807.     strcpybuff(path,CShellApp_app->end_path);
  2808.  
  2809.     /* Build top index */
  2810.     hts_buildtopindex(NULL,path, "");
  2811.  
  2812.     /* Check empty dirs and build .whtt */
  2813.     // FILE* fpo=fopen(fconcat(path,"/index.html"),"wb");
  2814.     //if (fpo) {
  2815.     {
  2816.       // verif_backblue(opt, path);    // gΘnΘrer gif
  2817.       //
  2818.       // Header
  2819.       //fprintf(fpo,toptemplate_header,
  2820.       //  "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
  2821.       //  );
  2822.       // chargement de la liste
  2823.       WIN32_FIND_DATA find;
  2824.       HANDLE h = FindFirstFile(CShellApp_app->end_path+"*.*",&find);
  2825.       if (h != INVALID_HANDLE_VALUE) {
  2826.         CString to_delete="";
  2827.         do {
  2828.           if (!(find.dwFileAttributes  & (FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN) ))
  2829.             if (strcmp(find.cFileName,".."))
  2830.               if (strcmp(find.cFileName,"."))
  2831.                 if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2832.                   int r;
  2833.                   r=CheckDirInfo(CShellApp_app->end_path+find.cFileName);
  2834.                   if ((r>=0) && (r<=3)) {       /* vide, fichiers vides etc */
  2835.                     to_delete+=(CShellApp_app->end_path+find.cFileName+"\n");
  2836.                   } else {      /* non vide */
  2837.                     char iname[HTS_URLMAXSIZE*2],iname2[HTS_URLMAXSIZE*2];
  2838.                     strcpybuff(iname,CShellApp_app->end_path);
  2839.                     strcatbuff(iname,find.cFileName);
  2840.                     strcatbuff(iname,"\\");
  2841.                     strcpybuff(iname2,iname);
  2842.                     strcatbuff(iname,"index.html");
  2843.                     strcatbuff(iname2,"\\hts-cache\\winprofile.ini");
  2844.                     if (fexist(iname)) {
  2845.                       char hname[HTS_URLMAXSIZE*2];
  2846.                       strcpybuff(hname,find.cFileName);
  2847.                       escape_check_url(hname);
  2848.                       // Body
  2849.                       //fprintf(fpo,toptemplate_body,
  2850.                       //  hname,
  2851.                       //  find.cFileName
  2852.                       //  );
  2853.                     }
  2854.                     
  2855.                     if ((fexist(iname)) || (fexist(iname2)) ) {
  2856.                       // vΘrifier existence de .whtt
  2857.                       strcpybuff(iname,CShellApp_app->end_path);
  2858.                       strcatbuff(iname,find.cFileName);
  2859.                       strcatbuff(iname,".whtt");
  2860.                       if (!fexist(iname)) {
  2861.                         FILE* fp=fopen(iname,"wb");
  2862.                         if (fp) fclose(fp);
  2863.                       }
  2864.                       
  2865.                     }
  2866.                   }
  2867.                 } else {    /* effacer .whtt qui ne pointent vers rien */
  2868.                   CString iname=CShellApp_app->end_path+find.cFileName;
  2869.                   if (iname.Right(5).CompareNoCase(".whtt")==0) {
  2870.                     CString rname=iname.Left(iname.GetLength()-5)+"\\index.html";
  2871.                     CString rname2=iname.Left(iname.GetLength()-5)+"\\hts-cache\\winprofile.ini";
  2872.                     if ( (!fexist((char*)LPCTSTR(rname))) && (!fexist((char*)LPCTSTR(rname2))) ) {
  2873.                       remove(iname);
  2874.                     }
  2875.                   }
  2876.                 }
  2877.         } while(FindNextFile(h,&find));
  2878.         FindClose(h);
  2879.         if (check_empty) {
  2880.           while(to_delete.GetLength()>0) {
  2881.             int pos=to_delete.Find('\n');
  2882.             if (pos) {
  2883.               CString path=to_delete.Left(pos);
  2884.               to_delete=to_delete.Mid(pos+1);
  2885.               CString str;
  2886.               str.Format(LANG_DELETEEMPTYCONF,path);
  2887.               if (AfxMessageBox(str,MB_OKCANCEL)==IDOK) {
  2888.                 /* Θliminer au besoin le .whtt */
  2889.                 DeleteFile(path+".whtt");
  2890.                 if (!RemoveEmptyDir(path))
  2891.                   AfxMessageBox(LANG_ERRORDEL);
  2892.               }
  2893.             } else
  2894.               to_delete="";
  2895.           }
  2896.         }
  2897.       }
  2898.       // Footer
  2899.       //fprintf(fpo,toptemplate_footer,
  2900.       //  "<!-- Mirror and index made by HTTrack Website Copier/"HTTRACK_VERSION" "HTTRACK_AFF_AUTHORS" -->"
  2901.       //  );
  2902.       //fclose(fpo);
  2903.     }
  2904.     
  2905.   }
  2906.  
  2907.   /*
  2908.   if (toptemplate_header)
  2909.     freet(toptemplate_header);
  2910.   if (toptemplate_body)
  2911.     freet(toptemplate_body);
  2912.   if (toptemplate_footer)
  2913.     freet(toptemplate_footer);
  2914.   */
  2915. }
  2916.  
  2917. /*
  2918. -1 : error
  2919. 0 : directory is empty
  2920. 1 : empty directories inside
  2921. 2 : empty files inside
  2922. 3 : 1 + 2
  2923. 4 : not empty
  2924. */
  2925. int CheckDirInfo(CString path) {
  2926.   CWaitCursor wait;
  2927.   
  2928.   if (path.Right(1)!="\\")
  2929.     path+="\\";
  2930.   
  2931.   // Pour FindFirstFile/FindNextFile
  2932.   WIN32_FIND_DATA find;
  2933.   HANDLE h = FindFirstFile(path+"*.*",&find);
  2934.   
  2935.   // accessible
  2936.   if (h!=INVALID_HANDLE_VALUE) {
  2937.     int return_code=0;
  2938.     do {
  2939.       if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_SYSTEM )) {
  2940.         if (strcmp(find.cFileName,"..")) {
  2941.           if (strcmp(find.cFileName,".")) {
  2942.             if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2943.               return_code|=1;
  2944.               int r=CheckDirInfo(path+find.cFileName);
  2945.               if (r==4)
  2946.                 return_code=4;
  2947.               else
  2948.                 return_code|=r;
  2949.             } else {
  2950.               return_code|=2;
  2951.               if ((find.nFileSizeLow) || (find.nFileSizeHigh))
  2952.                 return_code=4;
  2953.             }
  2954.           }
  2955.         }
  2956.       }
  2957.     } while(FindNextFile(h,&find) && !((return_code & 4)) );
  2958.     FindClose(h);
  2959.     return return_code;
  2960.   } else
  2961.     return -1;
  2962. }
  2963.  
  2964. /*
  2965. Remove Empty Dir
  2966. */
  2967. BOOL RemoveEmptyDir(CString path) {
  2968.   CWaitCursor wait;
  2969.   
  2970.   SetCurrentDirectory("C:\\");
  2971.   
  2972.   if (path.Right(1)!="\\")
  2973.     path+="\\";
  2974.   
  2975.   // Pour FindFirstFile/FindNextFile
  2976.   WIN32_FIND_DATA find;
  2977.   HANDLE h = FindFirstFile(path+"*.*",&find);
  2978.   
  2979.   // accessible
  2980.   if (h!=INVALID_HANDLE_VALUE) {
  2981.     do {
  2982.       if (!(find.dwFileAttributes  & FILE_ATTRIBUTE_SYSTEM )) {
  2983.         if (strcmp(find.cFileName,"..")) {
  2984.           if (strcmp(find.cFileName,".")) {
  2985.             if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY ) {
  2986.               if (!RemoveEmptyDir(path+find.cFileName)) {
  2987.                 FindClose(h);
  2988.                 return 0;
  2989.               }
  2990.             } else {
  2991.               if ((!find.nFileSizeLow) && (!find.nFileSizeHigh))
  2992.                 if (!DeleteFile(path+find.cFileName)) {
  2993.                   FindClose(h);
  2994.                   return 0;
  2995.                 }
  2996.             }
  2997.           }
  2998.         }
  2999.       }
  3000.     } while(FindNextFile(h,&find));
  3001.     FindClose(h);
  3002.     
  3003.     SetCurrentDirectory("C:\\");
  3004.     return RemoveDirectory(path.Left(path.GetLength()-1));
  3005.   } else
  3006.     return 0;
  3007.   return TRUE;
  3008. }
  3009.